Skip to content

Commit 9ac7bbd

Browse files
committed
add 67
1 parent 9c00ba3 commit 9ac7bbd

File tree

11 files changed

+49
-50
lines changed

11 files changed

+49
-50
lines changed

src/.vuepress/sidebar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export default sidebar({
101101
"0063",
102102
"0064",
103103
"0066",
104+
"0067",
104105
"0068",
105106
"0070",
106107
"0071",

src/leetcode/outline/plan/top_150_list.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ title: "面试经典 150 题"
266266

267267
| 题号 | 标题 | 题解 | 标签 | 难度 |
268268
| :------: | :------ | :------: | :------ | :------ |
269-
| 0067 | [二进制求和](https://leetcode.com/problems/add-binary/) | | [`位运算`](/leetcode/outline/tag/bit-manipulation.md) [`数学`](/leetcode/outline/tag/mathematics.md) [`字符串`](/leetcode/outline/tag/string.md) `1+` | <font color=#15bd66>Easy</font> |
269+
| 0067 | [二进制求和](https://leetcode.com/problems/add-binary/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0067) | [`位运算`](/leetcode/outline/tag/bit-manipulation.md) [`数学`](/leetcode/outline/tag/mathematics.md) [`字符串`](/leetcode/outline/tag/string.md) `1+` | <font color=#15bd66>Easy</font> |
270270
| 0190 | [颠倒二进制位](https://leetcode.com/problems/reverse-bits/) | | [`位运算`](/leetcode/outline/tag/bit-manipulation.md) [`分治`](/leetcode/outline/tag/divide-and-conquer.md) | <font color=#15bd66>Easy</font> |
271271
| 0191 | [位1的个数](https://leetcode.com/problems/number-of-1-bits/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0191) | [`位运算`](/leetcode/outline/tag/bit-manipulation.md) [`分治`](/leetcode/outline/tag/divide-and-conquer.md) | <font color=#15bd66>Easy</font> |
272272
| 0136 | [只出现一次的数字](https://leetcode.com/problems/single-number/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0136) | [`位运算`](/leetcode/outline/tag/bit-manipulation.md) [`数组`](/leetcode/outline/tag/array.md) | <font color=#15bd66>Easy</font> |

src/leetcode/outline/solution_list.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 1.3 LeetCode 题解
22

3-
已完成 326
3+
已完成 327
44

55
| 题号 | 标题 | 题解 | 标签 | 难度 |
66
| :------: | :------ | :------: | :------ | :------ |
@@ -61,6 +61,7 @@
6161
| 0063 | [不同路径 II](https://leetcode.com/problems/unique-paths-ii/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0063) | [`数组`](/leetcode/outline/tag/array.md) [`动态规划`](/leetcode/outline/tag/dynamic-programming.md) [`矩阵`](/leetcode/outline/tag/matrix.md) | <font color=#ffb800>Medium</font> |
6262
| 0064 | [最小路径和](https://leetcode.com/problems/minimum-path-sum/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0064) | [`数组`](/leetcode/outline/tag/array.md) [`动态规划`](/leetcode/outline/tag/dynamic-programming.md) [`矩阵`](/leetcode/outline/tag/matrix.md) | <font color=#ffb800>Medium</font> |
6363
| 0066 | [加一](https://leetcode.com/problems/plus-one/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0066) | [`数组`](/leetcode/outline/tag/array.md) [`数学`](/leetcode/outline/tag/mathematics.md) | <font color=#15bd66>Easy</font> |
64+
| 0067 | [二进制求和](https://leetcode.com/problems/add-binary/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0067) | [`位运算`](/leetcode/outline/tag/bit-manipulation.md) [`数学`](/leetcode/outline/tag/mathematics.md) [`字符串`](/leetcode/outline/tag/string.md) `1+` | <font color=#15bd66>Easy</font> |
6465
| 0068 | [文本左右对齐](https://leetcode.com/problems/text-justification/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0068) | [`数组`](/leetcode/outline/tag/array.md) [`字符串`](/leetcode/outline/tag/string.md) [`模拟`](/leetcode/outline/tag/simulation.md) | <font color=#ff334b>Hard</font> |
6566
| 0070 | [爬楼梯](https://leetcode.com/problems/climbing-stairs/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0070) | [`记忆化搜索`](/leetcode/outline/tag/memoization.md) [`数学`](/leetcode/outline/tag/mathematics.md) [`动态规划`](/leetcode/outline/tag/dynamic-programming.md) | <font color=#15bd66>Easy</font> |
6667
| 0071 | [简化路径](https://leetcode.com/problems/simplify-path/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0071) | [``](/leetcode/outline/tag/stack.md) [`字符串`](/leetcode/outline/tag/string.md) | <font color=#ffb800>Medium</font> |

src/leetcode/outline/tag/bit-manipulation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
| 题号 | 标题 | 题解 | 标签 | 难度 |
2222
| :------: | :------ | :------: | :------ | :------ |
2323
| 0029 | [两数相除](https://leetcode.com/problems/divide-two-integers/) | | [`位运算`](/leetcode/outline/tag/bit-manipulation.md) [`数学`](/leetcode/outline/tag/mathematics.md) | <font color=#ffb800>Medium</font> |
24-
| 0067 | [二进制求和](https://leetcode.com/problems/add-binary/) | | [`位运算`](/leetcode/outline/tag/bit-manipulation.md) [`数学`](/leetcode/outline/tag/mathematics.md) [`字符串`](/leetcode/outline/tag/string.md) `1+` | <font color=#15bd66>Easy</font> |
24+
| 0067 | [二进制求和](https://leetcode.com/problems/add-binary/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0067) | [`位运算`](/leetcode/outline/tag/bit-manipulation.md) [`数学`](/leetcode/outline/tag/mathematics.md) [`字符串`](/leetcode/outline/tag/string.md) `1+` | <font color=#15bd66>Easy</font> |
2525
| 0078 | [子集](https://leetcode.com/problems/subsets/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0078) | [`位运算`](/leetcode/outline/tag/bit-manipulation.md) [`数组`](/leetcode/outline/tag/array.md) [`回溯`](/leetcode/outline/tag/backtracking.md) | <font color=#ffb800>Medium</font> |
2626
| 0089 | [格雷编码](https://leetcode.com/problems/gray-code/) | | [`位运算`](/leetcode/outline/tag/bit-manipulation.md) [`数学`](/leetcode/outline/tag/mathematics.md) [`回溯`](/leetcode/outline/tag/backtracking.md) | <font color=#ffb800>Medium</font> |
2727
| 0090 | [子集 II](https://leetcode.com/problems/subsets-ii/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0090) | [`位运算`](/leetcode/outline/tag/bit-manipulation.md) [`数组`](/leetcode/outline/tag/array.md) [`回溯`](/leetcode/outline/tag/backtracking.md) | <font color=#ffb800>Medium</font> |

src/leetcode/outline/tag/mathematics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
| 0060 | [排列序列](https://leetcode.com/problems/permutation-sequence/) | | [`递归`](/leetcode/outline/tag/recursion.md) [`数学`](/leetcode/outline/tag/mathematics.md) | <font color=#ff334b>Hard</font> |
3333
| 0062 | [不同路径](https://leetcode.com/problems/unique-paths/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0062) | [`数学`](/leetcode/outline/tag/mathematics.md) [`动态规划`](/leetcode/outline/tag/dynamic-programming.md) [`组合数学`](/leetcode/outline/tag/combinatorics.md) | <font color=#ffb800>Medium</font> |
3434
| 0066 | [加一](https://leetcode.com/problems/plus-one/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0066) | [`数组`](/leetcode/outline/tag/array.md) [`数学`](/leetcode/outline/tag/mathematics.md) | <font color=#15bd66>Easy</font> |
35-
| 0067 | [二进制求和](https://leetcode.com/problems/add-binary/) | | [`位运算`](/leetcode/outline/tag/bit-manipulation.md) [`数学`](/leetcode/outline/tag/mathematics.md) [`字符串`](/leetcode/outline/tag/string.md) `1+` | <font color=#15bd66>Easy</font> |
35+
| 0067 | [二进制求和](https://leetcode.com/problems/add-binary/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0067) | [`位运算`](/leetcode/outline/tag/bit-manipulation.md) [`数学`](/leetcode/outline/tag/mathematics.md) [`字符串`](/leetcode/outline/tag/string.md) `1+` | <font color=#15bd66>Easy</font> |
3636
| 0069 | [x 的平方根](https://leetcode.com/problems/sqrtx/) | | [`数学`](/leetcode/outline/tag/mathematics.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) | <font color=#15bd66>Easy</font> |
3737
| 0070 | [爬楼梯](https://leetcode.com/problems/climbing-stairs/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0070) | [`记忆化搜索`](/leetcode/outline/tag/memoization.md) [`数学`](/leetcode/outline/tag/mathematics.md) [`动态规划`](/leetcode/outline/tag/dynamic-programming.md) | <font color=#15bd66>Easy</font> |
3838
| 0089 | [格雷编码](https://leetcode.com/problems/gray-code/) | | [`位运算`](/leetcode/outline/tag/bit-manipulation.md) [`数学`](/leetcode/outline/tag/mathematics.md) [`回溯`](/leetcode/outline/tag/backtracking.md) | <font color=#ffb800>Medium</font> |

src/leetcode/outline/tag/simulation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
| 0043 | [字符串相乘](https://leetcode.com/problems/multiply-strings/) | | [`数学`](/leetcode/outline/tag/mathematics.md) [`字符串`](/leetcode/outline/tag/string.md) [`模拟`](/leetcode/outline/tag/simulation.md) | <font color=#ffb800>Medium</font> |
2424
| 0054 | [螺旋矩阵](https://leetcode.com/problems/spiral-matrix/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0054) | [`数组`](/leetcode/outline/tag/array.md) [`矩阵`](/leetcode/outline/tag/matrix.md) [`模拟`](/leetcode/outline/tag/simulation.md) | <font color=#ffb800>Medium</font> |
2525
| 0059 | [螺旋矩阵 II](https://leetcode.com/problems/spiral-matrix-ii/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0059) | [`数组`](/leetcode/outline/tag/array.md) [`矩阵`](/leetcode/outline/tag/matrix.md) [`模拟`](/leetcode/outline/tag/simulation.md) | <font color=#ffb800>Medium</font> |
26-
| 0067 | [二进制求和](https://leetcode.com/problems/add-binary/) | | [`位运算`](/leetcode/outline/tag/bit-manipulation.md) [`数学`](/leetcode/outline/tag/mathematics.md) [`字符串`](/leetcode/outline/tag/string.md) `1+` | <font color=#15bd66>Easy</font> |
26+
| 0067 | [二进制求和](https://leetcode.com/problems/add-binary/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0067) | [`位运算`](/leetcode/outline/tag/bit-manipulation.md) [`数学`](/leetcode/outline/tag/mathematics.md) [`字符串`](/leetcode/outline/tag/string.md) `1+` | <font color=#15bd66>Easy</font> |
2727
| 0068 | [文本左右对齐](https://leetcode.com/problems/text-justification/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0068) | [`数组`](/leetcode/outline/tag/array.md) [`字符串`](/leetcode/outline/tag/string.md) [`模拟`](/leetcode/outline/tag/simulation.md) | <font color=#ff334b>Hard</font> |
2828
| 0157 | [用 Read4 读取 N 个字符](https://leetcode.com/problems/read-n-characters-given-read4/) | | [`字符串`](/leetcode/outline/tag/string.md) [`交互`](/leetcode/outline/tag/interaction.md) [`模拟`](/leetcode/outline/tag/simulation.md) | <font color=#15bd66>Easy</font> |
2929
| 0158 | [用 Read4 读取 N 个字符 II](https://leetcode.com/problems/read-n-characters-given-read4-ii-call-multiple-times/) | | [`字符串`](/leetcode/outline/tag/string.md) [`交互`](/leetcode/outline/tag/interaction.md) [`模拟`](/leetcode/outline/tag/simulation.md) | <font color=#ff334b>Hard</font> |

src/leetcode/outline/tag/string.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
| 0049 | [字母异位词分组](https://leetcode.com/problems/group-anagrams/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0049) | [`数组`](/leetcode/outline/tag/array.md) [`哈希表`](/leetcode/outline/tag/hash-table.md) [`字符串`](/leetcode/outline/tag/string.md) `1+` | <font color=#ffb800>Medium</font> |
4141
| 0058 | [最后一个单词的长度](https://leetcode.com/problems/length-of-last-word/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0058) | [`字符串`](/leetcode/outline/tag/string.md) | <font color=#15bd66>Easy</font> |
4242
| 0065 | [有效数字](https://leetcode.com/problems/valid-number/) | | [`字符串`](/leetcode/outline/tag/string.md) | <font color=#ff334b>Hard</font> |
43-
| 0067 | [二进制求和](https://leetcode.com/problems/add-binary/) | | [`位运算`](/leetcode/outline/tag/bit-manipulation.md) [`数学`](/leetcode/outline/tag/mathematics.md) [`字符串`](/leetcode/outline/tag/string.md) `1+` | <font color=#15bd66>Easy</font> |
43+
| 0067 | [二进制求和](https://leetcode.com/problems/add-binary/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0067) | [`位运算`](/leetcode/outline/tag/bit-manipulation.md) [`数学`](/leetcode/outline/tag/mathematics.md) [`字符串`](/leetcode/outline/tag/string.md) `1+` | <font color=#15bd66>Easy</font> |
4444
| 0068 | [文本左右对齐](https://leetcode.com/problems/text-justification/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0068) | [`数组`](/leetcode/outline/tag/array.md) [`字符串`](/leetcode/outline/tag/string.md) [`模拟`](/leetcode/outline/tag/simulation.md) | <font color=#ff334b>Hard</font> |
4545
| 0071 | [简化路径](https://leetcode.com/problems/simplify-path/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0071) | [``](/leetcode/outline/tag/stack.md) [`字符串`](/leetcode/outline/tag/string.md) | <font color=#ffb800>Medium</font> |
4646
| 0072 | [编辑距离](https://leetcode.com/problems/edit-distance/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0072) | [`字符串`](/leetcode/outline/tag/string.md) [`动态规划`](/leetcode/outline/tag/dynamic-programming.md) | <font color=#ff334b>Hard</font> |

src/leetcode/problem/0057.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Return `intervals` _after the insertion_.
6464
2. 注意边界情况
6565

6666
- 1. 若区间数组为空(例如:`intervals = [], newInterval = [1,2]`),则直接返回 `newInterval`
67-
- 2. 当循环遍历到区间数组的最后一个时(例如:intervals = [[2,3]], newInterval = [1,4]),由于后面不会再出现情况 2 了,所以最后要将合并后的区间放入返回数组中。
67+
- 2. 当循环遍历到区间数组的最后一个时(例如:`intervals = [[2,3]], newInterval = [1,4]`),由于后面不会再出现情况 2 了,所以最后要将合并后的区间放入返回数组中。
6868

6969
## 代码
7070

assets/output/0067.md renamed to src/leetcode/problem/0067.md

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# [67. Add Binary](https://leetcode.com/problems/add-binary/)
22

3+
🟢 <font color=#15bd66>Easy</font>&emsp; 🔖&ensp; [`位运算`](/leetcode/outline/tag/bit-manipulation.md) [`数学`](/leetcode/outline/tag/mathematics.md) [`字符串`](/leetcode/outline/tag/string.md) [`模拟`](/leetcode/outline/tag/simulation.md)&emsp; 🔗&ensp;[`LeetCode`](https://leetcode.com/problems/add-binary/)
4+
35
## 题目
46

57
Given two binary strings `a` and `b`, return _their sum as a binary string_.
@@ -45,28 +47,21 @@ Given two binary strings `a` and `b`, return _their sum as a binary string_.
4547
* @return {string}
4648
*/
4749
var addBinary = function (a, b) {
48-
let l1 = a.split("");
49-
let l2 = b.split("");
50-
let res = [];
51-
let sum = 0;
52-
let carry = 0;
53-
while (l1.length || l2.length || sum > 0) {
54-
if (l1.length) {
55-
sum += Number(l1.pop());
56-
}
57-
if (l2.length) {
58-
sum += Number(l2.pop());
59-
}
60-
if (sum >= 2) {
61-
carry = 1;
62-
sum -= 2;
63-
}
64-
res.unshift(sum);
65-
sum = carry;
66-
carry = 0;
67-
}
68-
69-
return res.join("");
50+
// res 存储结果,carry 记录进位
51+
let m = a.length,
52+
n = b.length,
53+
res = '',
54+
carry = 0,
55+
i = 0;
56+
// 模拟加法逻辑
57+
while (i < Math.max(m, n)) {
58+
let num = carry;
59+
num += Number(a[m - i - 1] || 0) + Number(b[n - i - 1] || 0);
60+
res = (num % 2) + res;
61+
carry = Math.floor(num / 2);
62+
i++;
63+
}
64+
return carry ? carry + res : res;
7065
};
7166
```
7267

src/leetcode/problem/0117.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66

77
Given a binary tree
88

9-
struct Node {
10-
int val;
11-
Node *left;
12-
Node *right;
13-
Node *next;
14-
}
9+
```javascript
10+
struct Node {
11+
int val;
12+
Node *left;
13+
Node *right;
14+
Node *next;
15+
}
16+
```
1517

1618
Populate each next pointer to point to its next right node. If there is no
1719
next right node, the next pointer should be set to `NULL`.
@@ -48,14 +50,13 @@ Initially, all next pointers are set to `NULL`.
4850

4951
给定一个二叉树:
5052

51-
```jsx
53+
```js
5254
struct Node {
5355
int val;
5456
Node *left;
5557
Node *right;
5658
Node *next;
5759
}
58-
5960
```
6061

6162
填充它的每个 `next` 指针,让这个指针指向其下一个右侧节点。如果找不到下一个右侧节点,则将 `next` 指针设置为 `NULL`。初始状态下,所有  `next` 指针都被设置为 `NULL`
@@ -75,18 +76,18 @@ struct Node {
7576
* @return {Node}
7677
*/
7778
var connect = function (root) {
78-
if (!root) return root;
79-
let queue = [root];
80-
while (queue.length) {
81-
let len = queue.length;
82-
for (let i = 0; i < len; i++) {
83-
if (i + 1 < len) queue[i].next = queue[i + 1];
84-
if (queue[i].left) queue.push(queue[i].left);
85-
if (queue[i].right) queue.push(queue[i].right);
86-
}
87-
queue = queue.slice(len);
88-
}
89-
return root;
79+
if (!root) return root;
80+
let queue = [root];
81+
while (queue.length) {
82+
let len = queue.length;
83+
for (let i = 0; i < len; i++) {
84+
if (i + 1 < len) queue[i].next = queue[i + 1];
85+
if (queue[i].left) queue.push(queue[i].left);
86+
if (queue[i].right) queue.push(queue[i].right);
87+
}
88+
queue = queue.slice(len);
89+
}
90+
return root;
9091
};
9192
```
9293

0 commit comments

Comments
 (0)