Skip to content

Commit 43d7b9d

Browse files
committed
Add solution #1780
1 parent 5ba5fee commit 43d7b9d

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@
171171
1475|[Final Prices With a Special Discount in a Shop](./1475-final-prices-with-a-special-discount-in-a-shop.js)|Easy|
172172
1486|[XOR Operation in an Array](./1486-xor-operation-in-an-array.js)|Easy|
173173
1598|[Crawler Log Folder](./1598-crawler-log-folder.js)|Easy|
174+
1780|[Check if Number is a Sum of Powers of Three](./1780-check-if-number-is-a-sum-of-powers-of-three.js)|Medium|
174175
1880|[Check if Word Equals Summation of Two Words](./1880-check-if-word-equals-summation-of-two-words.js)|Easy|
175176
1929|[Concatenation of Array](./1929-concatenation-of-array.js)|Easy|
176177
2000|[Reverse Prefix of Word](./2000-reverse-prefix-of-word.js)|Easy|
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* 1780. Check if Number is a Sum of Powers of Three
3+
* https://leetcode.com/problems/check-if-number-is-a-sum-of-powers-of-three/
4+
* Difficulty: Medium
5+
*
6+
* Given an integer n, return true if it is possible to represent n as the sum
7+
* of distinct powers of three. Otherwise, return false.
8+
*
9+
* An integer y is a power of three if there exists an integer x such that y == 3x.
10+
*/
11+
12+
/**
13+
* @param {number} n
14+
* @return {boolean}
15+
*/
16+
var checkPowersOfThree = function(n) {
17+
while (n) {
18+
if (n % 3 === 2) {
19+
return 0;
20+
}
21+
n = n / 3 >> 0;
22+
}
23+
return 1;
24+
};

0 commit comments

Comments
 (0)