leetcode Power of Three

leetcode Power of Three 题目:https://leetcode.com/problems/power-of-three/

解题思路:不断除以3如果等于1,是3的幂次方,如果不是,不是3的幂次方。

public boolean isPowerOfThree(int n) {
		if(n==0){
			return false;
		}
		while(n%3==0){
			n=n/3;
		}
		if(n==1){
			return true;
		}
		return false;
	}

猜你喜欢

转载自blog.csdn.net/u011243684/article/details/84980234