leetcode链接:326. Power of Three
Given an integer, write a function to determine if it is a power of three.
Follow up:
Could you do it without using any loop / recursion?
General universal solution:
|
|
By the above, but the topic that best try acyclic or recursive solution.
I feel such a method is a little tricky. For example, to find the int
largest factor in the range of 3, so that any multiple of 3 n
may be divisible thereof.
|
|
或者将上述代码压缩到一行:
|
|
pow
函数在头文件math.h
中。
同类题:
原文:大专栏 判断int是否为3的幂—— Leetcode(326)