File tree 3 files changed +13
-14
lines changed
3 files changed +13
-14
lines changed Original file line number Diff line number Diff line change 1
1
| 题目 | 题解 | 难度 | 推荐指数 |
2
2
| ------------------------------------------------------------ | ------------------------------------------------------------ | ---- | -------- |
3
- | [ 90. 子集 II] ( https://leetcode-cn.com/problems/subsets-ii/ ) | [ LeetCode 题解链接] ( https://leetcode-cn.com/problems/subsets-ii/solution/gong-shui-san-xie-yi-ti-shuang-jie-hui-s-g77q/ ) | 中等 | 🤩🤩🤩🤩 |
4
3
| [ 137. 只出现一次的数字 II] ( https://leetcode-cn.com/problems/single-number-ii/ ) | [ LeetCode 题解链接] ( https://leetcode-cn.com/problems/single-number-ii/solution/gong-shui-san-xie-yi-ti-san-jie-ha-xi-bi-fku8/ ) | 中等 | 🤩🤩🤩 |
5
4
| [ 190. 颠倒二进制位] ( https://leetcode-cn.com/problems/reverse-bits/ ) | [ LeetCode 题解链接] ( https://leetcode-cn.com/problems/reverse-bits/solution/yi-ti-san-jie-dui-cheng-wei-zhu-wei-fen-ub1hi/ ) | 简单 | 🤩🤩🤩 |
6
5
| [ 191. 位1的个数] ( https://leetcode-cn.com/problems/number-of-1-bits/ ) | [ LeetCode 题解链接] ( https://leetcode-cn.com/problems/number-of-1-bits/solution/yi-ti-san-jie-wei-shu-jian-cha-you-yi-to-av1r/ ) | 简单 | 🤩🤩🤩 |
Original file line number Diff line number Diff line change @@ -41,10 +41,10 @@ Tag : 「位运算」
41
41
42
42
### 「位数检查」解法
43
43
44
- ![ image.png] ( https://pic.leetcode-cn.com/1616375441-WGCssd-image.png )
45
-
46
44
一个朴素的做法是,对 ` int ` 的每一位进行检查,并统计 $1$ 的个数。
47
45
46
+ ![ image.png] ( https://pic.leetcode-cn.com/1616375441-WGCssd-image.png )
47
+
48
48
代码:
49
49
``` Java []
50
50
public class Solution {
@@ -64,8 +64,6 @@ public class Solution {
64
64
65
65
### 「右移统计」解法
66
66
67
- ![ image.png] ( https://pic.leetcode-cn.com/1616375636-fXCFNF-image.png )
68
-
69
67
对于方法一,即使 $n$ 的高位均为是 $0$,我们也会对此进行循环检查。
70
68
71
69
因此另外一个做法是:通过 ` n & 1 ` 来统计当前 $n$ 的最低位是否为 $1$,同时每次直接对 $n$ 进行右移并高位补 0。
@@ -74,6 +72,8 @@ public class Solution {
74
72
75
73
这样的做法,可以确保只会循环到最高位的 $1$。
76
74
75
+ ![ image.png] ( https://pic.leetcode-cn.com/1616375636-fXCFNF-image.png )
76
+
77
77
代码:
78
78
``` Java []
79
79
public class Solution {
@@ -124,10 +124,10 @@ public class Solution {
124
124
125
125
### 「分组统计」解法
126
126
127
- ![ image.png] ( https://pic.leetcode-cn.com/1616378128-yBWadF-image.png )
128
-
129
127
以上三种解法都是 $O(k)$ 的,事实上我们可以通过分组统计的方式,做到比 $O(k)$ 更低的复杂度。
130
128
129
+ ![ image.png] ( https://pic.leetcode-cn.com/1616378128-yBWadF-image.png )
130
+
131
131
代码:
132
132
``` Java []
133
133
public class Solution {
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ Tag : 「位运算」、「分治」
23
23
输入:11111111111111111111111111111101
24
24
输出:31
25
25
解释:输入的二进制串 11111111111111111111111111111101 中,共有 31 位为 '1'。
26
- ```
26
+ ```
27
27
28
28
提示:
29
29
* 输入必须是长度为 32 的 二进制串 。
@@ -32,10 +32,10 @@ Tag : 「位运算」、「分治」
32
32
33
33
### 「位数检查」解法
34
34
35
- 
36
-
37
35
一个朴素的做法是,对 ` int ` 的每一位进行检查,并统计 $1$ 的个数。
38
36
37
+ ![ image.png] ( https://pic.leetcode-cn.com/1616375441-WGCssd-image.png )
38
+
39
39
代码:
40
40
``` Java []
41
41
public class Solution {
@@ -55,8 +55,6 @@ public class Solution {
55
55
56
56
### 「右移统计」解法
57
57
58
- ![ image.png] ( https://pic.leetcode-cn.com/1616375636-fXCFNF-image.png )
59
-
60
58
对于方法一,即使 $n$ 的高位均为是 $0$,我们也会对此进行循环检查。
61
59
62
60
因此另外一个做法是:通过 ` n & 1 ` 来统计当前 $n$ 的最低位是否为 $1$,同时每次直接对 $n$ 进行右移并高位补 0。
@@ -65,6 +63,8 @@ public class Solution {
65
63
66
64
这样的做法,可以确保只会循环到最高位的 $1$。
67
65
66
+ ![ image.png] ( https://pic.leetcode-cn.com/1616375636-fXCFNF-image.png )
67
+
68
68
代码:
69
69
``` Java []
70
70
public class Solution {
@@ -115,10 +115,10 @@ public class Solution {
115
115
116
116
### 「分组统计」解法
117
117
118
- ![ image.png] ( https://pic.leetcode-cn.com/1616378128-yBWadF-image.png )
119
-
120
118
以上三种解法都是 $O(k)$ 的,事实上我们可以通过分组统计的方式,做到比 $O(k)$ 更低的复杂度。
121
119
120
+ ![ image.png] ( https://pic.leetcode-cn.com/1616378128-yBWadF-image.png )
121
+
122
122
代码:
123
123
``` Java []
124
124
public class Solution {
You can’t perform that action at this time.
0 commit comments