Skip to content

Commit 647a653

Browse files
committed
提交231 2的幂
1 parent 2e1f9cf commit 647a653

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

231.2的幂/solution.html

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Document</title>
8+
</head>
9+
<body>
10+
<script>
11+
// Source : https://leetcode.com/problems/power-of-two/
12+
// Author : 悬笔e绝
13+
// Date : 2019-01-19
14+
15+
/**
16+
* @param {number} n
17+
* @return {boolean}
18+
*/
19+
20+
var isPowerOfTwo = function(n) {
21+
//基于2取底数,~~取整
22+
var tmp = ~~(Math.log(n) / Math.log(2));
23+
// 1左移tmp位,就是2的tmp次方
24+
return n === (1 << tmp);
25+
};
26+
27+
</script>
28+
</body>
29+
</html>

0 commit comments

Comments
 (0)