有一个 leetcode 测试326。使用 java 的数学方法的三的幂:
public class Solution {
public boolean isPowerOfThree(int n) {
return (Math.log(n) / Math.log(3) + epsilon) % 1 <= 2 * epsilon;
}
}
当我打算将此解决方案转换为 Golang Like
import "math"
func isPowerOfThree(n int) bool {
return (math.Log10(float64(n)) / math.Log10(3)) % 1 == 0.0
}
然后出现编译错误,例如
Line 4: Char 53: invalid operation: math.Log10(float64(n)) / math.Log10(3) % 1 (operator % not defined on float64) (solution.go)
我检查了数学包,但没有像运算符这样受支持的函数,有没有像Golang这样的%有效运算符?%多谢 :)
有只小跳蛙
相关分类