p326

LeetCode p326 Power of Three 题解

1.题目:

Given an integer, write a function to determine if it is a power of three.

题意:

输入一个int型数判断他是否是3的n次方

2.解题思路:

1162261467 = 3^19, 3^20 比 int 大

3.代码


[title] [] [url] [link text]
1
2
3
4
5
6
7
 
public class Solution {
public boolean isPowerOfThree(int n) {
return ( n>0 && 1162261467%n==0);
}
}


4.一些总结: