mirror of
https://github.com/ShusenTang/LeetCode.git
synced 2024-09-02 14:20:01 +00:00
add 54 in README
This commit is contained in:
parent
81e719f104
commit
46cdd5b251
@ -44,6 +44,7 @@ LeetCode solutions with Chinese explanation. LeetCode中文题解。
|
|||||||
| 49 |[Group Anagrams](https://leetcode.com/problems/group-anagrams/)|[C++](https://github.com/ShusenTang/LeetCode/blob/master/solutions/49.%20Group%20Anagrams.md)|Medium| |
|
| 49 |[Group Anagrams](https://leetcode.com/problems/group-anagrams/)|[C++](https://github.com/ShusenTang/LeetCode/blob/master/solutions/49.%20Group%20Anagrams.md)|Medium| |
|
||||||
| 50 |[Pow(x, n)](https://leetcode.com/problems/powx-n/)|[C++](https://github.com/ShusenTang/LeetCode/blob/master/solutions/50.%20Pow(x%2C%20n).md)|Medium| |
|
| 50 |[Pow(x, n)](https://leetcode.com/problems/powx-n/)|[C++](https://github.com/ShusenTang/LeetCode/blob/master/solutions/50.%20Pow(x%2C%20n).md)|Medium| |
|
||||||
| 53 |[Maximum Subarray](https://leetcode.com/problems/maximum-subarray)|[C++](https://github.com/ShusenTang/LeetCode/blob/master/solutions/53.%20Maximum%20Subarray.md)|Easy| |
|
| 53 |[Maximum Subarray](https://leetcode.com/problems/maximum-subarray)|[C++](https://github.com/ShusenTang/LeetCode/blob/master/solutions/53.%20Maximum%20Subarray.md)|Easy| |
|
||||||
|
| 54 |[Spiral Matrix](https://leetcode.com/problems/spiral-matrix/)|[C++](https://github.com/ShusenTang/LeetCode/blob/master/solutions/54.%20Spiral%20Matrix.md)|Medium| |
|
||||||
| 58 |[Length of Last Word](https://leetcode.com/problems/length-of-last-word)|[C++](https://github.com/ShusenTang/LeetCode/blob/master/solutions/58.%20Length%20of%20Last%20Word.md)|Easy| |
|
| 58 |[Length of Last Word](https://leetcode.com/problems/length-of-last-word)|[C++](https://github.com/ShusenTang/LeetCode/blob/master/solutions/58.%20Length%20of%20Last%20Word.md)|Easy| |
|
||||||
| 66 |[Plus One](https://leetcode.com/problems/plus-one)|[C++](https://github.com/ShusenTang/LeetCode/blob/master/solutions/66.%20Plus%20One.md)|Easy| |
|
| 66 |[Plus One](https://leetcode.com/problems/plus-one)|[C++](https://github.com/ShusenTang/LeetCode/blob/master/solutions/66.%20Plus%20One.md)|Easy| |
|
||||||
| 67 |[Add Binary](https://leetcode.com/problems/add-binary)|[C++](https://github.com/ShusenTang/LeetCode/blob/master/solutions/67.%20Add%20Binary.md)|Easy| |
|
| 67 |[Add Binary](https://leetcode.com/problems/add-binary)|[C++](https://github.com/ShusenTang/LeetCode/blob/master/solutions/67.%20Add%20Binary.md)|Easy| |
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
4. 竖直(向上)移动m-2次;
|
4. 竖直(向上)移动m-2次;
|
||||||
5. ......
|
5. ......
|
||||||
|
|
||||||
直到移动次数变为0即遍历完成。所以该过程有两个周期,一个是水平与竖直的周期,周期为2;另一个就是具体方向的周期,周期为4。我们可以用一个大小为2的初始值为{n, m-1}的数组steps记录还剩下的两个方向的步数。为了方便四个方向的移动运算,我们可以定义一个二维的const数组dirs,其值为`{{0, 1}, {1, 0}, {0, -1}, {-1, 0}}`。
|
直到移动次数变为0即遍历完成。所以该过程有两个周期,一个是水平与竖直的周期,周期为2;另一个就是具体方向的周期,周期为4。我们可以用一个大小为2的初始值为[n, m-1]的数组steps记录还剩下的两个方向的步数。为了方便四个方向的移动运算,我们可以定义一个二维的const数组dirs,其值为`[[0, 1], [1, 0], [0, -1], [-1, 0]]`。
|
||||||
|
|
||||||
此方法可以很方便地推广到逆时针螺旋遍历,只需要把方向(右、下、左、上)改成(下、右、上、左)即可,即改动一下dirs的元素排列顺序即可。
|
此方法可以很方便地推广到逆时针螺旋遍历,只需要把方向(右、下、左、上)改成(下、右、上、左)即可,即改动一下dirs的元素排列顺序即可。
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user