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?
Credits:
Special thanks to @dietpepsi for adding this problem and creating all test cases.
前提学习:
Java Math的floor,round,ceil函数小结
想法:
3^x=n
log(3^x) = log(n)
x log(3) = log(n)
x = log(n) / log(3)
We need to
largest number power of 3, is 1162261467, we can use this to calculate the float precision. 0.0000000001 at least
Math.log(1162261468)/log(3)
private static

这是一个关于LeetCode问题326的讨论,该问题要求编写一个函数检查一个整数是否为3的幂。文章提到了可以不使用循环或递归的方式来解决,并提供了相关的想法和可能的解决方案。
订阅专栏 解锁全文
323

被折叠的 条评论
为什么被折叠?



