15算法课程 326. Power of Three
2017-12-22 23:22
246 查看
Given an integer, write a function to determine if it is a power of three.
Follow up:
Could you do it without using any loop / recursion?
solution:
一行代码解决
code:
Given an integer, write a function to determine if it is a power of three.
Follow up:
Could you do it without using any loop / recursion?
solution:
一行代码解决
code:
class Solution { public: bool isPowerOfThree(int n) { return (n > 0 && 1162261467 % n == 0); } };
相关文章推荐
- 15算法课程 191. Number of 1 Bits
- 15算法课程 35. Search Insert Position
- 15算法课程 225. Implement Stack using Queues
- 15算法课程 160. Intersection of Two Linked Lists
- 15算法课程 108. Convert Sorted Array to Binary Search Tree
- 15算法课程 169. Majority Element
- 15算法课程 122. Best Time to Buy and Sell Stock II
- 15算法课程 292. Nim Game
- 15算法课程 231. Power of Two
- 15算法课程 53. Maximum Subarray
- 15算法课程 100. Same Tree
- 15算法课程 110. Balanced Binary Tree
- 15算法课程 171. Excel Sheet Column Number
- 15算法课程 303. Range Sum Query - Immutable
- 15算法课程 202. Happy Number
- 15算法课程 232. Implement Queue using Stacks
- 15算法课程 58. Length of Last Word
- 15算法课程 226. Invert Binary Tree
- 15算法课程 342. Power of Four
- 15算法课程 204. Count Primes