LeetCode Top Interview Questions 326. Power of Three (Java版; Easy)
题目描述
Given an integer, write a function to determine if it is a power of three.
Example 1:
Input: 27
Output: true
Example 2:
Input: 0
Output: false
Example 3:
Input: 9
Output: true
Example 4:
Input: 45
Output: false
Follow up:
Could you do it without using any loop / recursion?
第一次做; 数学分析:3^19的因数只有20个, 分别是3^0,…3^19
classSolution{publicbooleanisPowerOfThree(int n){// 1162261467 is 3^19, 3^20 is bigger than int return(n>0&&1162261467%n==0)}}
LeetCode Top Interview Questions 326. Power of Three (Java版; Easy)
welcome to my blogLeetCode Top Interview Questions 326. Power of Three (Java版; Easy)题目描述Given an integer, write a function to determine if it is a power of three.Example 1:Input: 27Output: tru...