方法一
思路:求底,判断结果是否是整数
1 | // Runtime: 88 ms, faster than 18.54% of JavaScript online submissions for Power of Two. |
方法二
思路:位运算,因为2的指数结果二进制一定是以1开头,剩下位数都是0的串。
1 | // Runtime: 96 ms, faster than 15.25% of JavaScript online submissions for Power of Two. |
test cases
1 | test("test1", () => { |