326. Power of Three \ 258. Add Digits \ 263. Ugly Number \ 231. Power of Two
来源:互联网 发布:天龙八部2 源码下载 编辑:程序博客网 时间:2024/06/15 20:17
- Ugly Number
- Add Digits
- Power of Three
- Power of Two
263. Ugly Number
class Solution {public: bool isUgly(int num) { int ungly_set[] = {2, 3, 5}; if(num <= 0) return false; while(num != 1) { for(int i = 0; i <= 2; i++) { if(!(num%ungly_set[i])) { num = num/ungly_set[i]; break; } else if(i == 2) return false; } } return true; }};
258. Add Digits
典型的digit root的题目 digital root。
class Solution {public: int addDigits(int num) { return 1 + (num - 1) % 9; }};
326. Power of Three
class Solution {public: bool isPowerOfThree(int n) { if(n <= 0) return false; int f = floor(log10(n)/log10(3)); int c = ceil(log10(n)/log10(3)); return f == c; }};
class Solution {public: bool isPowerOfThree(int n) { return fmod(log10(n)/log10(3), 1)==0; }};
231. Power of Two
class Solution {public: bool isPowerOfTwo(int n) { return fmod(log10(n)/log10(2), 1) == 0; }};
class Solution {public: bool isPowerOfTwo(int n) { return n > 0 && !(n&(n-1)); }};
class Solution {public: bool isPowerOfTwo(int n) { return!(n&n-1)*n>0; }};
0 0
- 326. Power of Three \ 258. Add Digits \ 263. Ugly Number \ 231. Power of Two
- LeetCode 231. Power of Two & 326. Power of Three
- 326. Power of Three ,231. Power of Two ,
- Leetcode 231. Power of Two & 326. Power of Three & 342. Power of Four
- 【leetcode】326. Power of Three 231. Power of Two 342. Power of Four
- [LeetCode]231. Power of Two&326. Power of Three&342. Power of Four
- leetcode 231. Power of Two & 326. Power of Three & 342. Power of Four
- [LeetCode] Power of Three | Power of Two
- Power of two,power of three,power of four
- leetcode- Number of 1 bits, power of two, power of three
- 326. Power of Three
- 326. Power of Three
- 326. Power of Three
- 326. Power of Three
- 326. Power of Three
- 326. Power of Three
- 326. Power of Three
- 326. Power of Three
- Stay Hungry,Stay Foolish的解读
- SVM的最优化问题
- HDU2089-不要62
- LOVE2D-04-加载文字和图片
- 从现在开始写博客
- 326. Power of Three \ 258. Add Digits \ 263. Ugly Number \ 231. Power of Two
- JavaScript中高阶函数的使用例子
- Educational Codeforces Round 17
- 1.Phaser游戏引擎介绍
- 2.phaser创建游戏和场景
- 3.phaser点击图片
- 492. Construct the Rectangle (E)
- 关于一些java的零碎的知识点
- java实现循环列队