@@ -28,7 +28,7 @@ diff=(n&(n-1))^n
28
28
29
29
## 常见题目
30
30
31
- [ single-number] ( https://leetcode-cn.com/problems/single-number/ )
31
+ ### [ single-number] ( https://leetcode-cn.com/problems/single-number/ )
32
32
33
33
> 给定一个** 非空** 整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次。找出那个只出现了一次的元素。
34
34
@@ -43,7 +43,7 @@ class Solution:
43
43
return out
44
44
```
45
45
46
- [ single-number-ii] ( https://leetcode-cn.com/problems/single-number-ii/ )
46
+ ### [ single-number-ii] ( https://leetcode-cn.com/problems/single-number-ii/ )
47
47
48
48
> 给定一个** 非空** 整数数组,除了某个元素只出现一次以外,其余每个元素均出现了三次。找出那个只出现了一次的元素。
49
49
@@ -59,7 +59,7 @@ class Solution:
59
59
return seen_once
60
60
```
61
61
62
- [ single-number-iii] ( https://leetcode-cn.com/problems/single-number-iii/ )
62
+ ### [ single-number-iii] ( https://leetcode-cn.com/problems/single-number-iii/ )
63
63
64
64
> 给定一个整数数组 ` nums ` ,其中恰好有两个元素只出现一次,其余所有元素均出现两次。 找出只出现一次的那两个元素。
65
65
@@ -83,7 +83,7 @@ class Solution:
83
83
return [x, bitmask^ x]
84
84
```
85
85
86
- [ number-of-1-bits] ( https://leetcode-cn.com/problems/number-of-1-bits/ )
86
+ ### [ number-of-1-bits] ( https://leetcode-cn.com/problems/number-of-1-bits/ )
87
87
88
88
> 编写一个函数,输入是一个无符号整数,返回其二进制表达式中数字位数为 ‘1’ 的个数(也被称为[ 汉明重量] ( https://baike.baidu.com/item/%E6%B1%89%E6%98%8E%E9%87%8D%E9%87%8F ) )。
89
89
@@ -97,11 +97,11 @@ class Solution:
97
97
return num_ones
98
98
```
99
99
100
- [ counting-bits] ( https://leetcode-cn.com/problems/counting-bits/ )
100
+ ### [ counting-bits] ( https://leetcode-cn.com/problems/counting-bits/ )
101
101
102
102
> 给定一个非负整数 ** num** 。对于 0 ≤ i ≤ num 范围中的每个数字 i ,计算其二进制数中的 1 的数目并将它们作为数组返回。
103
103
104
- 思路:利用上一题的解法容易想到 O(nk) 的解法,k 为位数。但是实际上可以利用动态规划将复杂度降到 O(n),想法其实也很简单,即当前数的 1 个数等于比它少一个 1 的数的结果加 1。下面给出三种 DP 解法
104
+ - 思路:利用上一题的解法容易想到 O(nk) 的解法,k 为位数。但是实际上可以利用动态规划将复杂度降到 O(n),想法其实也很简单,即当前数的 1 个数等于比它少一个 1 的数的结果加 1。下面给出三种 DP 解法
105
105
106
106
``` Python
107
107
# x <- x // 2
@@ -148,7 +148,7 @@ class Solution:
148
148
return num_ones
149
149
```
150
150
151
- [ reverse-bits] ( https://leetcode-cn.com/problems/reverse-bits/ )
151
+ ### [ reverse-bits] ( https://leetcode-cn.com/problems/reverse-bits/ )
152
152
153
153
> 颠倒给定的 32 位无符号整数的二进制位。
154
154
@@ -172,7 +172,7 @@ class Solution:
172
172
return (byte * 0x 0202020202 & 0x 010884422010 ) % 1023
173
173
```
174
174
175
- [ bitwise-and-of-numbers-range] ( https://leetcode-cn.com/problems/bitwise-and-of-numbers-range/ )
175
+ ### [ bitwise-and-of-numbers-range] ( https://leetcode-cn.com/problems/bitwise-and-of-numbers-range/ )
176
176
177
177
> 给定范围 [ m, n] ,其中 0 <= m <= n <= 2147483647,返回此范围内所有数字的按位与(包含 m, n 两端点)。
178
178
0 commit comments