mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-10 00:09:06 +01:00
problems(kt): add „326. Power of Three“
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
13c5b4b30a
commit
3bcb7469d9
1 changed files with 13 additions and 0 deletions
13
problems/power-of-three.kt
Normal file
13
problems/power-of-three.kt
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
class Solution {
|
||||||
|
fun isPowerOfThree(n: Int): Boolean {
|
||||||
|
if (n < 1) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var x = n
|
||||||
|
while (x % 3 == 0) {
|
||||||
|
x /= 3
|
||||||
|
}
|
||||||
|
return x == 1
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue