题目

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

分析

32bit表示的int，3的整次幂最大数为1162261467，所以只需判断给定整数n能否被该最大数整除即可。

代码

class Solution {
public:
bool isPowerOfThree(int n) {
return n > 0 && 1162261467 % n == 0;
}
};

leetcode326. Power of Three

326. Power of ThreeGiven an integer, write a function to determine if it is a power of three.Follow ...

LeetCode 326. Power of Three 解题报告

LeetCode 326. Power of Three 解题报告

<LeetCode OJ> 326. Power of Three

326. Power of Three My Submissions Question Total Accepted: 1159 Total Submissions: 3275 Difficu...

Leetcode 231. Power of Two & 326. Power of Three & 342. Power of Four

231. Power of Two   Total Accepted: 69528 Total Submissions: 190898 Difficulty: Easy Given an ...

LeetCode|Power of three

LeetCode Power of Three

leetcode- Number of 1 bits, power of two, power of three

leetcode- Number of 1 bits, power of two, power of three
• aaasy
• 2016年04月23日 22:13
• 86

举报原因： 您举报文章：LeetCode（326） Power of Three 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)