Skip to content

Commit 0c7ba38

Browse files
committed
✨refactor: Update 191、剑指 Offer 15
1 parent e236285 commit 0c7ba38

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

Index/位运算.md

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
| 题目 | 题解 | 难度 | 推荐指数 |
22
| ------------------------------------------------------------ | ------------------------------------------------------------ | ---- | -------- |
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/) | 中等 | 🤩🤩🤩🤩 |
43
| [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/) | 中等 | 🤩🤩🤩 |
54
| [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/) | 简单 | 🤩🤩🤩 |
65
| [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/) | 简单 | 🤩🤩🤩 |

LeetCode/191-200/191. 位1的个数(简单).md

+6-6
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ Tag : 「位运算」
4141

4242
### 「位数检查」解法
4343

44-
![image.png](https://pic.leetcode-cn.com/1616375441-WGCssd-image.png)
45-
4644
一个朴素的做法是,对 `int` 的每一位进行检查,并统计 $1$ 的个数。
4745

46+
![image.png](https://pic.leetcode-cn.com/1616375441-WGCssd-image.png)
47+
4848
代码:
4949
```Java []
5050
public class Solution {
@@ -64,8 +64,6 @@ public class Solution {
6464

6565
### 「右移统计」解法
6666

67-
![image.png](https://pic.leetcode-cn.com/1616375636-fXCFNF-image.png)
68-
6967
对于方法一,即使 $n$ 的高位均为是 $0$,我们也会对此进行循环检查。
7068

7169
因此另外一个做法是:通过 `n & 1` 来统计当前 $n$ 的最低位是否为 $1$,同时每次直接对 $n$ 进行右移并高位补 0。
@@ -74,6 +72,8 @@ public class Solution {
7472

7573
这样的做法,可以确保只会循环到最高位的 $1$。
7674

75+
![image.png](https://pic.leetcode-cn.com/1616375636-fXCFNF-image.png)
76+
7777
代码:
7878
```Java []
7979
public class Solution {
@@ -124,10 +124,10 @@ public class Solution {
124124

125125
### 「分组统计」解法
126126

127-
![image.png](https://pic.leetcode-cn.com/1616378128-yBWadF-image.png)
128-
129127
以上三种解法都是 $O(k)$ 的,事实上我们可以通过分组统计的方式,做到比 $O(k)$ 更低的复杂度。
130128

129+
![image.png](https://pic.leetcode-cn.com/1616378128-yBWadF-image.png)
130+
131131
代码:
132132
```Java []
133133
public class Solution {

LeetCode/剑指 Offer/剑指 Offer 15. 二进制中1的个数(简单).md

+7-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Tag : 「位运算」、「分治」
2323
输入:11111111111111111111111111111101
2424
输出:31
2525
解释:输入的二进制串 11111111111111111111111111111101 中,共有 31 位为 '1'。
26-
``` 
26+
```
2727

2828
提示:
2929
* 输入必须是长度为 32 的 二进制串 。
@@ -32,10 +32,10 @@ Tag : 「位运算」、「分治」
3232

3333
### 「位数检查」解法
3434

35-
![image.png](https://pic.leetcode-cn.com/1616375441-WGCssd-image.png)
36-
3735
一个朴素的做法是,对 `int` 的每一位进行检查,并统计 $1$ 的个数。
3836

37+
![image.png](https://pic.leetcode-cn.com/1616375441-WGCssd-image.png)
38+
3939
代码:
4040
```Java []
4141
public class Solution {
@@ -55,8 +55,6 @@ public class Solution {
5555

5656
### 「右移统计」解法
5757

58-
![image.png](https://pic.leetcode-cn.com/1616375636-fXCFNF-image.png)
59-
6058
对于方法一,即使 $n$ 的高位均为是 $0$,我们也会对此进行循环检查。
6159

6260
因此另外一个做法是:通过 `n & 1` 来统计当前 $n$ 的最低位是否为 $1$,同时每次直接对 $n$ 进行右移并高位补 0。
@@ -65,6 +63,8 @@ public class Solution {
6563

6664
这样的做法,可以确保只会循环到最高位的 $1$。
6765

66+
![image.png](https://pic.leetcode-cn.com/1616375636-fXCFNF-image.png)
67+
6868
代码:
6969
```Java []
7070
public class Solution {
@@ -115,10 +115,10 @@ public class Solution {
115115

116116
### 「分组统计」解法
117117

118-
![image.png](https://pic.leetcode-cn.com/1616378128-yBWadF-image.png)
119-
120118
以上三种解法都是 $O(k)$ 的,事实上我们可以通过分组统计的方式,做到比 $O(k)$ 更低的复杂度。
121119

120+
![image.png](https://pic.leetcode-cn.com/1616378128-yBWadF-image.png)
121+
122122
代码:
123123
```Java []
124124
public class Solution {

0 commit comments

Comments
 (0)