Skip to content

Commit d141821

Browse files
committed
add 731
1 parent 868bfb4 commit d141821

File tree

11 files changed

+188
-124
lines changed

11 files changed

+188
-124
lines changed

assets/output/0731.md

Lines changed: 0 additions & 70 deletions
This file was deleted.

src/.vuepress/sidebar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ export default sidebar({
366366
"0714",
367367
"0724",
368368
"0729",
369+
"0731",
369370
"0739",
370371
"0772",
371372
"0783"

src/leetcode/ds/tree.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ class NumArray {
11271127
| 题号 | 标题 | 题解 | 标签 | 难度 |
11281128
| :------: | :------ | :------: | :------ | :------ |
11291129
| 0729 | [我的日程安排表 I](https://leetcode.com/problems/my-calendar-i/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0729) | [`设计`](/leetcode/outline/tag/design.md) [`线段树`](/leetcode/outline/tag/segment-tree.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) `1+` | <font color=#ffb800>Medium</font> |
1130-
| 0731 | [我的日程安排表 II](https://leetcode.com/problems/my-calendar-ii/) | | [`设计`](/leetcode/outline/tag/design.md) [`线段树`](/leetcode/outline/tag/segment-tree.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) `1+` | <font color=#ffb800>Medium</font> |
1130+
| 0731 | [我的日程安排表 II](https://leetcode.com/problems/my-calendar-ii/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0731) | [`设计`](/leetcode/outline/tag/design.md) [`线段树`](/leetcode/outline/tag/segment-tree.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) `1+` | <font color=#ffb800>Medium</font> |
11311131
| 0732 | [我的日程安排表 III](https://leetcode.com/problems/my-calendar-iii/) | | [`设计`](/leetcode/outline/tag/design.md) [`线段树`](/leetcode/outline/tag/segment-tree.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) `1+` | <font color=#ff334b>Hard</font> |
11321132

11331133
* 扫描线问题

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-
已完成 358
3+
已完成 359
44

55
| 题号 | 标题 | 题解 | 标签 | 难度 |
66
| :------: | :------ | :------: | :------ | :------ |
@@ -272,6 +272,7 @@
272272
| 0714 | [买卖股票的最佳时机含手续费](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0714) | [`贪心`](/leetcode/outline/tag/greedy.md) [`数组`](/leetcode/outline/tag/array.md) | <font color=#ffb800>Medium</font> |
273273
| 0724 | [寻找数组的中心下标](https://leetcode.com/problems/find-pivot-index/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0724) | [`数组`](/leetcode/outline/tag/array.md) [`前缀和`](/leetcode/outline/tag/prefix-sum.md) | <font color=#15bd66>Easy</font> |
274274
| 0729 | [我的日程安排表 I](https://leetcode.com/problems/my-calendar-i/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0729) | [`设计`](/leetcode/outline/tag/design.md) [`线段树`](/leetcode/outline/tag/segment-tree.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) `1+` | <font color=#ffb800>Medium</font> |
275+
| 0731 | [我的日程安排表 II](https://leetcode.com/problems/my-calendar-ii/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0731) | [`设计`](/leetcode/outline/tag/design.md) [`线段树`](/leetcode/outline/tag/segment-tree.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) `1+` | <font color=#ffb800>Medium</font> |
275276
| 0739 | [每日温度](https://leetcode.com/problems/daily-temperatures/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0739) | [``](/leetcode/outline/tag/stack.md) [`数组`](/leetcode/outline/tag/array.md) [`单调栈`](/leetcode/outline/tag/monotonic-stack.md) | <font color=#ffb800>Medium</font> |
276277
| 0772 | [基本计算器 III](https://leetcode.com/problems/basic-calculator-iii/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0772) | [``](/leetcode/outline/tag/stack.md) [`递归`](/leetcode/outline/tag/recursion.md) [`数学`](/leetcode/outline/tag/mathematics.md) `1+` | <font color=#ff334b>Hard</font> |
277278
| 0783 | [二叉搜索树节点最小距离](https://leetcode.com/problems/minimum-distance-between-bst-nodes/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0783) | [``](/leetcode/outline/tag/tree.md) [`深度优先搜索`](/leetcode/outline/tag/depth-first-search.md) [`广度优先搜索`](/leetcode/outline/tag/breadth-first-search.md) `2+` | <font color=#15bd66>Easy</font> |

src/leetcode/outline/tag/binary-search.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
| 0718 | [最长重复子数组](https://leetcode.com/problems/maximum-length-of-repeated-subarray/) | | [`数组`](/leetcode/outline/tag/array.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) [`动态规划`](/leetcode/outline/tag/dynamic-programming.md) `3+` | <font color=#ffb800>Medium</font> |
7777
| 0719 | [找出第 K 小的数对距离](https://leetcode.com/problems/find-k-th-smallest-pair-distance/) | | [`数组`](/leetcode/outline/tag/array.md) [`双指针`](/leetcode/outline/tag/two-pointers.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) `1+` | <font color=#ff334b>Hard</font> |
7878
| 0729 | [我的日程安排表 I](https://leetcode.com/problems/my-calendar-i/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0729) | [`设计`](/leetcode/outline/tag/design.md) [`线段树`](/leetcode/outline/tag/segment-tree.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) `1+` | <font color=#ffb800>Medium</font> |
79-
| 0731 | [我的日程安排表 II](https://leetcode.com/problems/my-calendar-ii/) | | [`设计`](/leetcode/outline/tag/design.md) [`线段树`](/leetcode/outline/tag/segment-tree.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) `1+` | <font color=#ffb800>Medium</font> |
79+
| 0731 | [我的日程安排表 II](https://leetcode.com/problems/my-calendar-ii/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0731) | [`设计`](/leetcode/outline/tag/design.md) [`线段树`](/leetcode/outline/tag/segment-tree.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) `1+` | <font color=#ffb800>Medium</font> |
8080
| 0732 | [我的日程安排表 III](https://leetcode.com/problems/my-calendar-iii/) | | [`设计`](/leetcode/outline/tag/design.md) [`线段树`](/leetcode/outline/tag/segment-tree.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) `1+` | <font color=#ff334b>Hard</font> |
8181
| 0744 | [寻找比目标字母大的最小字母](https://leetcode.com/problems/find-smallest-letter-greater-than-target/) | | [`数组`](/leetcode/outline/tag/array.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) | <font color=#15bd66>Easy</font> |
8282
| 0754 | [到达终点数字](https://leetcode.com/problems/reach-a-number/) | | [`数学`](/leetcode/outline/tag/mathematics.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) | <font color=#ffb800>Medium</font> |

src/leetcode/outline/tag/design.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
| 0715 | [Range 模块](https://leetcode.com/problems/range-module/) | | [`设计`](/leetcode/outline/tag/design.md) [`线段树`](/leetcode/outline/tag/segment-tree.md) [`有序集合`](/leetcode/outline/tag/ordered-set.md) | <font color=#ff334b>Hard</font> |
7373
| 0716 | [最大栈](https://leetcode.com/problems/max-stack/) | | [``](/leetcode/outline/tag/stack.md) [`设计`](/leetcode/outline/tag/design.md) [`链表`](/leetcode/outline/tag/linked-list.md) `2+` | <font color=#ff334b>Hard</font> |
7474
| 0729 | [我的日程安排表 I](https://leetcode.com/problems/my-calendar-i/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0729) | [`设计`](/leetcode/outline/tag/design.md) [`线段树`](/leetcode/outline/tag/segment-tree.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) `1+` | <font color=#ffb800>Medium</font> |
75-
| 0731 | [我的日程安排表 II](https://leetcode.com/problems/my-calendar-ii/) | | [`设计`](/leetcode/outline/tag/design.md) [`线段树`](/leetcode/outline/tag/segment-tree.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) `1+` | <font color=#ffb800>Medium</font> |
75+
| 0731 | [我的日程安排表 II](https://leetcode.com/problems/my-calendar-ii/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0731) | [`设计`](/leetcode/outline/tag/design.md) [`线段树`](/leetcode/outline/tag/segment-tree.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) `1+` | <font color=#ffb800>Medium</font> |
7676
| 0732 | [我的日程安排表 III](https://leetcode.com/problems/my-calendar-iii/) | | [`设计`](/leetcode/outline/tag/design.md) [`线段树`](/leetcode/outline/tag/segment-tree.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) `1+` | <font color=#ff334b>Hard</font> |
7777
| 0745 | [前缀和后缀搜索](https://leetcode.com/problems/prefix-and-suffix-search/) | | [`设计`](/leetcode/outline/tag/design.md) [`字典树`](/leetcode/outline/tag/trie.md) [`哈希表`](/leetcode/outline/tag/hash-table.md) `1+` | <font color=#ff334b>Hard</font> |
7878
| 0855 | [考场就座](https://leetcode.com/problems/exam-room/) | | [`设计`](/leetcode/outline/tag/design.md) [`有序集合`](/leetcode/outline/tag/ordered-set.md) [`堆(优先队列)`](/leetcode/outline/tag/heap-priority-queue.md) | <font color=#ffb800>Medium</font> |

src/leetcode/outline/tag/ordered-set.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
| 0715 | [Range 模块](https://leetcode.com/problems/range-module/) | | [`设计`](/leetcode/outline/tag/design.md) [`线段树`](/leetcode/outline/tag/segment-tree.md) [`有序集合`](/leetcode/outline/tag/ordered-set.md) | <font color=#ff334b>Hard</font> |
3636
| 0716 | [最大栈](https://leetcode.com/problems/max-stack/) | | [``](/leetcode/outline/tag/stack.md) [`设计`](/leetcode/outline/tag/design.md) [`链表`](/leetcode/outline/tag/linked-list.md) `2+` | <font color=#ff334b>Hard</font> |
3737
| 0729 | [我的日程安排表 I](https://leetcode.com/problems/my-calendar-i/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0729) | [`设计`](/leetcode/outline/tag/design.md) [`线段树`](/leetcode/outline/tag/segment-tree.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) `1+` | <font color=#ffb800>Medium</font> |
38-
| 0731 | [我的日程安排表 II](https://leetcode.com/problems/my-calendar-ii/) | | [`设计`](/leetcode/outline/tag/design.md) [`线段树`](/leetcode/outline/tag/segment-tree.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) `1+` | <font color=#ffb800>Medium</font> |
38+
| 0731 | [我的日程安排表 II](https://leetcode.com/problems/my-calendar-ii/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0731) | [`设计`](/leetcode/outline/tag/design.md) [`线段树`](/leetcode/outline/tag/segment-tree.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) `1+` | <font color=#ffb800>Medium</font> |
3939
| 0732 | [我的日程安排表 III](https://leetcode.com/problems/my-calendar-iii/) | | [`设计`](/leetcode/outline/tag/design.md) [`线段树`](/leetcode/outline/tag/segment-tree.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) `1+` | <font color=#ff334b>Hard</font> |
4040
| 0850 | [矩形面积 II](https://leetcode.com/problems/rectangle-area-ii/) | | [`线段树`](/leetcode/outline/tag/segment-tree.md) [`数组`](/leetcode/outline/tag/array.md) [`有序集合`](/leetcode/outline/tag/ordered-set.md) `1+` | <font color=#ff334b>Hard</font> |
4141
| 0855 | [考场就座](https://leetcode.com/problems/exam-room/) | | [`设计`](/leetcode/outline/tag/design.md) [`有序集合`](/leetcode/outline/tag/ordered-set.md) [`堆(优先队列)`](/leetcode/outline/tag/heap-priority-queue.md) | <font color=#ffb800>Medium</font> |

src/leetcode/outline/tag/segment-tree.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
| 0699 | [掉落的方块](https://leetcode.com/problems/falling-squares/) | | [`线段树`](/leetcode/outline/tag/segment-tree.md) [`数组`](/leetcode/outline/tag/array.md) [`有序集合`](/leetcode/outline/tag/ordered-set.md) | <font color=#ff334b>Hard</font> |
3232
| 0715 | [Range 模块](https://leetcode.com/problems/range-module/) | | [`设计`](/leetcode/outline/tag/design.md) [`线段树`](/leetcode/outline/tag/segment-tree.md) [`有序集合`](/leetcode/outline/tag/ordered-set.md) | <font color=#ff334b>Hard</font> |
3333
| 0729 | [我的日程安排表 I](https://leetcode.com/problems/my-calendar-i/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0729) | [`设计`](/leetcode/outline/tag/design.md) [`线段树`](/leetcode/outline/tag/segment-tree.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) `1+` | <font color=#ffb800>Medium</font> |
34-
| 0731 | [我的日程安排表 II](https://leetcode.com/problems/my-calendar-ii/) | | [`设计`](/leetcode/outline/tag/design.md) [`线段树`](/leetcode/outline/tag/segment-tree.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) `1+` | <font color=#ffb800>Medium</font> |
34+
| 0731 | [我的日程安排表 II](https://leetcode.com/problems/my-calendar-ii/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0731) | [`设计`](/leetcode/outline/tag/design.md) [`线段树`](/leetcode/outline/tag/segment-tree.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) `1+` | <font color=#ffb800>Medium</font> |
3535
| 0732 | [我的日程安排表 III](https://leetcode.com/problems/my-calendar-iii/) | | [`设计`](/leetcode/outline/tag/design.md) [`线段树`](/leetcode/outline/tag/segment-tree.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) `1+` | <font color=#ff334b>Hard</font> |
3636
| 0850 | [矩形面积 II](https://leetcode.com/problems/rectangle-area-ii/) | | [`线段树`](/leetcode/outline/tag/segment-tree.md) [`数组`](/leetcode/outline/tag/array.md) [`有序集合`](/leetcode/outline/tag/ordered-set.md) `1+` | <font color=#ff334b>Hard</font> |
3737
| 1157 | [子数组中占绝大多数的元素](https://leetcode.com/problems/online-majority-element-in-subarray/) | | [`设计`](/leetcode/outline/tag/design.md) [`树状数组`](/leetcode/outline/tag/fenwick-tree.md) [`线段树`](/leetcode/outline/tag/segment-tree.md) `2+` | <font color=#ff334b>Hard</font> |

src/leetcode/problem/0498.md

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,16 @@ array in a diagonal order_.
3939

4040
## 解题思路
4141

42-
- 给出一个二维数组,要求按照如图的方式遍历整个数组。
43-
- 这一题用模拟的方式就可以解出来。需要注意的是边界条件:比如二维数组为空,二维数组退化为一行或者一列,退化为一个元素。具体例子见测试用例。
44-
- 解题关键是在判断下一个位置,将矩阵想像成一个 X,Y 坐标轴。那么可分为以下几种情况,
45-
1、斜角向右上遍历时,
46-
当右上角在坐标轴内, 正常计算 即, x+1(X 轴向右移动), y-1(Y 轴向上移动)
47-
当右上角在坐标轴外,那么当前位置只能在 第一行 X 坐标轴 ,或者 最后一列 Y 坐标轴,即判断该两种情况下,应该 X 坐标往右,或者 Y 坐标往上
48-
2、同理 斜角向下遍历时
49-
当左下角在坐标轴内,正常计算 即, x-1(X 轴向右移动), y+1(Y 轴向下移动)
50-
当左下角在坐标轴外,那么当前位置只能在 第一列 Y 坐标轴,或者 最后一行 X 坐标轴,即判断该两种情况下,应该 X 坐标往左,或者 Y 坐标往下
42+
这一题用模拟的方式就可以解出来。需要注意的是边界条件:比如二维数组为空,二维数组退化为一行或者一列,退化为一个元素。具体例子见测试用例。
43+
44+
解题关键是在判断下一个位置,将矩阵想像成一个 `X`,`Y` 坐标轴。那么可分为以下几种情况,
45+
46+
1. 斜角向右上遍历时,
47+
- 当右上角在坐标轴内, 正常计算 即, `x+1`(`X` 轴向右移动),` y-1`(`Y` 轴向上移动)
48+
- 当右上角在坐标轴外,那么当前位置只能在 第一行 `X` 坐标轴 ,或者 最后一列 `Y` 坐标轴,即判断该两种情况下,应该 `X` 坐标往右,或者 `Y` 坐标往上
49+
2. 同理 斜角向下遍历时
50+
- 当左下角在坐标轴内,正常计算 即, `x-1`(`X` 轴向右移动), `y+1`(`Y` 轴向下移动)
51+
- 当左下角在坐标轴外,那么当前位置只能在 第一列 `Y` 坐标轴,或者 最后一行 `X` 坐标轴,即判断该两种情况下,应该 `X` 坐标往左,或者 `Y` 坐标往下
5152

5253
## 代码
5354

@@ -57,44 +58,44 @@ array in a diagonal order_.
5758
* @return {number[]}
5859
*/
5960
var findDiagonalOrder = function (mat) {
60-
const rowLen = mat.length;
61-
const colLen = mat[0].length;
62-
const total = rowLen * colLen;
63-
const result = [];
64-
let k = 0;
65-
let row = 0;
66-
let col = 0;
67-
let direction = "up";
68-
69-
while (k < total) {
70-
result.push(mat[row][col]);
71-
72-
if (direction === "up") {
73-
if (row === 0 && col < colLen - 1) {
74-
col++;
75-
direction = "down";
76-
} else if (col === colLen - 1) {
77-
row++;
78-
direction = "down";
79-
} else {
80-
row--;
81-
col++;
82-
}
83-
} else {
84-
if (col === 0 && row < rowLen - 1) {
85-
row++;
86-
direction = "up";
87-
} else if (row === rowLen - 1) {
88-
col++;
89-
direction = "up";
90-
} else {
91-
row++;
92-
col--;
93-
}
94-
}
95-
k++;
96-
}
97-
return result;
61+
const rowLen = mat.length;
62+
const colLen = mat[0].length;
63+
const total = rowLen * colLen;
64+
const result = [];
65+
let k = 0;
66+
let row = 0;
67+
let col = 0;
68+
let direction = 'up';
69+
70+
while (k < total) {
71+
result.push(mat[row][col]);
72+
73+
if (direction === 'up') {
74+
if (row === 0 && col < colLen - 1) {
75+
col++;
76+
direction = 'down';
77+
} else if (col === colLen - 1) {
78+
row++;
79+
direction = 'down';
80+
} else {
81+
row--;
82+
col++;
83+
}
84+
} else {
85+
if (col === 0 && row < rowLen - 1) {
86+
row++;
87+
direction = 'up';
88+
} else if (row === rowLen - 1) {
89+
col++;
90+
direction = 'up';
91+
} else {
92+
row++;
93+
col--;
94+
}
95+
}
96+
k++;
97+
}
98+
return result;
9899
};
99100
```
100101

0 commit comments

Comments
 (0)