LeetCode(326) Power of Three

原创 2016年08月29日 21:50:02

题目

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

分析


本题判断给定一个整数是否为3的整次幂,不可用递归和循环。

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笔记:326. Power of Three

判断一个整数是否是3的次方数

【leetcode】326. Power of Three

一、题目描述 Given an integer, write a function to determine if it is a power of three. Follow up:...

<LeetCode OJ> 326. Power of Three

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

326. Power of Three(C++)

题目:Given an integer, write a function to determine if it is a power of three. 给一个整数,判断它是不是3的幂数 Fo...

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.题目如下: Given an integer, write a function to determine if it is...

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
  • aaasy
  • 2016年04月23日 22:13
  • 86
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:LeetCode(326) Power of Three
举报原因:
原因补充:

(最多只允许输入30个字)