Power of Three

发布时间:2017-2-22 21:22:58 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"Power of Three ",主要涉及到Power of Three 方面的内容,对于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?

 1 public class Solution { 2     public boolean isPowerOfThree(int n) { 3         if (n == 0)    return false; 4  5         if (n == 1) return true; 6  7         if (n > 1) 8             return n % 3 == 0 && isPowerOfThree(n / 3); 9         else10             return false;11     }12 }

上一篇:c++标准库
下一篇:从话费战到流量战,三大运营商联合互联网巨头再掀圈地运动

相关文章

关键词: Power of Three

相关评论