We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
给定一个整数,写一个函数来判断它是否是 3 的幂次方。
示例 1:
输入: 27 输出: true 示例 2:
输入: 0 输出: false 示例 3:
输入: 9 输出: true 示例 4:
输入: 45 输出: false 进阶: 你能不使用循环或者递归来完成本题吗?
来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/power-of-three 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
解法: 不断除以3 确定最后的值, 然后判断是不是整除。
/** * @param {number} n * @return {boolean} */ var isPowerOfThree = function(n) { while(n>1){ n=n/3; } return n===1; };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
给定一个整数,写一个函数来判断它是否是 3 的幂次方。
示例 1:
输入: 27
输出: true
示例 2:
输入: 0
输出: false
示例 3:
输入: 9
输出: true
示例 4:
输入: 45
输出: false
进阶:
你能不使用循环或者递归来完成本题吗?
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/power-of-three
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
解法:
不断除以3 确定最后的值, 然后判断是不是整除。
The text was updated successfully, but these errors were encountered: