kt: add «1780. Check if Number is a Sum of Powers of Three»
URL: https://leetcode.com/problems/check-if-number-is-a-sum-of-powers-of-three/ Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
9eff71a1a7
commit
513547c2f2
1 changed files with 15 additions and 0 deletions
15
kt/check-if-number-is-a-sum-of-powers-of-three.kt
Normal file
15
kt/check-if-number-is-a-sum-of-powers-of-three.kt
Normal file
|
@ -0,0 +1,15 @@
|
|||
class Solution {
|
||||
fun checkPowersOfThree(n: Int): Boolean {
|
||||
var n = n
|
||||
|
||||
while (n > 0) {
|
||||
if (n % 3 > 1) {
|
||||
return false
|
||||
}
|
||||
|
||||
n /= 3
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue