Power of Three

来源:互联网 发布:好心分手 知乎 编辑:程序博客网 时间:2024/06/10 15:37

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?

方法:选出int类型中3的幂次方最大的数。

class Solution {public:    bool isPowerOfThree(int n) {         return ( n>0 &&  1162261467%n==0);    }};
0 0
原创粉丝点击