Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 16e395b

Browse files
✨ bitwise and of numbers range
1 parent 1cd56c6 commit 16e395b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

‎CATEGORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
* 二叉搜索树
4848

4949
- 位运算
50+
201
5051

5152
* 并查集
5253

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @param {number} m
3+
* @param {number} n
4+
* @return {number}
5+
*/
6+
7+
// HELP:
8+
9+
var rangeBitwiseAnd = function (m, n) {
10+
while (m < n) {
11+
// 抹去最右边的 1
12+
n = n & (n - 1);
13+
}
14+
15+
return n;
16+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /