美文网首页
326. Power of Three

326. Power of Three

作者: SilentDawn | 来源:发表于2018-09-26 19:48 被阅读0次

Problem

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?

Example

Input: 27
Output: true
Input: 0
Output: false
Input: 9
Output: true
Input: 45
Output: false

Code

static int var = [](){
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    return 0;
}();
class Solution {
public:
    bool isPowerOfThree(int n) {
        return n>0 && 1162261467%n==0;
    }
};

Result

326. Power of Three.png

相关文章

网友评论

      本文标题:326. Power of Three

      本文链接:https://www.haomeiwen.com/subject/nnmjoftx.html