326. Power of Three--LeetCode Record

Tong_hdj發表於2016-07-14

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?

水!

    func isPowerOfThree(n: Int) -> Bool {
        // 1162261467 is 3^19,  3^20 is bigger than int  
        return ( n>0 &&  1162261467%n==0);
    }

相關文章