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?
1 2 3 4 5 6 7 8 |
class Solution { public: bool isPowerOfThree(int n) { if(n <= 0) return false; return pow(3, (round)(log(n) / log(3))) == n; } }; |
❤ 点击这里 -> 订阅《PAT | 蓝桥 | LeetCode学习路径 & 刷题经验》by 柳婼