File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 171
171
1475|[ Final Prices With a Special Discount in a Shop] ( ./1475-final-prices-with-a-special-discount-in-a-shop.js ) |Easy|
172
172
1486|[ XOR Operation in an Array] ( ./1486-xor-operation-in-an-array.js ) |Easy|
173
173
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|
174
175
1880|[ Check if Word Equals Summation of Two Words] ( ./1880-check-if-word-equals-summation-of-two-words.js ) |Easy|
175
176
1929|[ Concatenation of Array] ( ./1929-concatenation-of-array.js ) |Easy|
176
177
2000|[ Reverse Prefix of Word] ( ./2000-reverse-prefix-of-word.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments