Skip to content

Commit 9d1e085

Browse files
add 1780
1 parent 572c608 commit 9d1e085

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

contest/src/main/java/com/github/contest/Execute.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.github.contest
22

33

4-
import com.github.contest.array.pivotArrayAlternativeSolution
4+
import com.github.contest.math.checkPowersOfThree
55
import java.util.TreeMap
66

77

@@ -11,7 +11,7 @@ import java.util.TreeMap
1111

1212
fun main() {
1313

14-
pivotArrayAlternativeSolution(intArrayOf(9, 12, 5, 10, 14, 3, 10), 10)
14+
checkPowersOfThree(12)
1515
}
1616

1717
fun generateTesting() {

contest/src/main/java/com/github/contest/array/AlternativeSolutionArray.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fun pivotArrayAlternativeSolution(nums: IntArray, pivot: Int): IntArray {
151151
equalCount--
152152
}
153153

154-
//Reverse the greater part
154+
155155
var start = lessIndex
156156
var end = n - 1
157157
while (start < end) {

contest/src/main/java/com/github/contest/math/MathLeetcode.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,19 @@ package com.github.contest.math
44
* 1025. Divisor Game
55
*/
66

7-
fun divisorGame(n: Int): Boolean = n % 2 == 0
7+
fun divisorGame(n: Int): Boolean = n % 2 == 0
8+
9+
/**
10+
* 1780. Check if Number is a Sum of Powers of Three
11+
*/
12+
13+
fun checkPowersOfThree(n: Int): Boolean {
14+
var num = n
15+
while (num > 0) {
16+
if (num % 3 == 2) {
17+
return false
18+
}
19+
num /= 3
20+
}
21+
return true
22+
}

0 commit comments

Comments
 (0)