Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
luzhipeng committed May 23, 2019
1 parent 1df79cd commit b256ae8
Show file tree
Hide file tree
Showing 20 changed files with 620 additions and 14 deletions.
17 changes: 11 additions & 6 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,17 @@ The data structures mainly includes:
- [0020.Valid Parentheses](./problems/20.validParentheses.md)
- [0026.remove-duplicates-from-sorted-array](./problems/26.remove-duplicates-from-sorted-array.md)
- [0088.merge-sorted-array](./problems/88.merge-sorted-array.md)
- [0104.maximum-depth-of-binary-tree](./problems/104.maximum-depth-of-binary-tree.md) 🆕
- [0121.best-time-to-buy-and-sell-stock](./problems/121.best-time-to-buy-and-sell-stock.md)
- [0122.best-time-to-buy-and-sell-stock-ii](./problems/122.best-time-to-buy-and-sell-stock-ii.md)
- [0136.single-number](./problems/136.single-number.md)
- [0155.min-stack](./problems/155.min-stack.md) 🆕
- [0167.two-sum-ii-input-array-is-sorted](./problems/167.two-sum-ii-input-array-is-sorted.md)
- [0172.factorial-trailing-zeroes](./problems/172.factorial-trailing-zeroes.md) 🆕
- [0169.majority-element](./problems/169.majority-element.md)
- [0190.reverse-bits](./problems/190.reverse-bits.md)
- [0191.number-of-1-bits](./problems/191.number-of-1-bits.md)
- [0198.house-robber](./problems/198.house-robber.md) 🆕
- [0198.house-robber](./problems/198.house-robber.md)
- [0203.remove-linked-list-elements](./problems/203.remove-linked-list-elements.md)
- [0206.reverse-linked-list](./problems/206.reverse-linked-list.md)
- [0219.contains-duplicate-ii](./problems/219.contains-duplicate-ii.md)
Expand All @@ -114,7 +116,8 @@ The data structures mainly includes:
- [0283.move-zeroes](./problems/283.move-zeroes.md)
- [0342.power-of-four](./problems/342.power-of-four.md) 🆕
- [0349.intersection-of-two-arrays](./problems/349.intersection-of-two-arrays.md)
- [0575.distribute-candies](./problems/575.distribute-candies.md) 🆕
- [0371.sum-of-two-integers](./problems/371.sum-of-two-integers.md) 🆕
- [0575.distribute-candies](./problems/575.distribute-candies.md)


#### Medium
Expand All @@ -131,11 +134,12 @@ The data structures mainly includes:
- [0047.permutations-ii](./problems/47.permutations-ii.md)
- [0055.jump-game](./problems/55.jump-game.md)
- [0062.unique-paths](./problems/62.unique-paths.md )
- [0073.set-matrix-zeroes](./problems/73.set-matrix-zeroes.md )🆕
- [0075.sort-colors](./problems/75.sort-colors.md)
- [0078.subsets](./problems/78.subsets.md)
- [0078.subsets](./problems/78.subsets.md)
- [0086.partition-list](./problems/86.partition-list.md)
- [0090.subsets-ii](./problems/90.subsets-ii.md)
- [0091.decode-ways](./problems/91.decode-ways.md) 🆕
- [0091.decode-ways](./problems/91.decode-ways.md)
- [0092.reverse-linked-list-ii](./problems/92.reverse-linked-list-ii.md)
- [0094.binary-tree-inorder-traversal](./problems/94.binary-tree-inorder-traversal.md)
- [0102.binary-tree-level-order-traversal](./problems/102.binary-tree-level-order-traversal.md)
Expand All @@ -147,8 +151,9 @@ The data structures mainly includes:
- [0199.binary-tree-right-side-view](./problems/199.binary-tree-right-side-view.md)
- [0201.bitwise-and-of-numbers-range](./problems/201.bitwise-and-of-numbers-range.md)
- [0208.implement-trie-prefix-tree](./problems/208.implement-trie-prefix-tree.md)
- [0209.minimum-size-subarray-sum](./problems/209.minimum-size-subarray-sum.md)
- [0236.lowest-common-ancestor-of-a-binary-tree](./problems/236.lowest-common-ancestor-of-a-binary-tree.md)
- [0209.minimum-size-subarray-sum](./problems/209.minimum-size-subarray-sum.md)
- [0230.kth-smallest-element-in-a-bst](./problems/230.kth-smallest-element-in-a-bst.md) 🆕
- [0236.lowest-common-ancestor-of-a-binary-tree](./problems/236.lowest-common-ancestor-of-a-binary-tree.md)🆕
- [0238.product-of-array-except-self](./problems/238.product-of-array-except-self.md) 🆕
- [0240.search-a-2-d-matrix-ii](./problems/240.search-a-2-d-matrix-ii.md)
- [0279.perfect-squares](./problems/279.perfect-squares.md)
Expand Down
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,17 @@ leetcode 题解,记录自己的 leetcode 解题之路。
- [0020.Valid Parentheses](./problems/20.validParentheses.md)
- [0026.remove-duplicates-from-sorted-array](./problems/26.remove-duplicates-from-sorted-array.md)
- [0088.merge-sorted-array](./problems/88.merge-sorted-array.md)
- [0104.maximum-depth-of-binary-tree](./problems/104.maximum-depth-of-binary-tree.md) 🆕
- [0121.best-time-to-buy-and-sell-stock](./problems/121.best-time-to-buy-and-sell-stock.md)
- [0122.best-time-to-buy-and-sell-stock-ii](./problems/122.best-time-to-buy-and-sell-stock-ii.md)
- [0136.single-number](./problems/136.single-number.md)
- [0155.min-stack](./problems/155.min-stack.md) 🆕
- [0167.two-sum-ii-input-array-is-sorted](./problems/167.two-sum-ii-input-array-is-sorted.md)
- [0172.factorial-trailing-zeroes](./problems/172.factorial-trailing-zeroes.md) 🆕
- [0169.majority-element](./problems/169.majority-element.md)
- [0190.reverse-bits](./problems/190.reverse-bits.md)
- [0191.number-of-1-bits](./problems/191.number-of-1-bits.md)
- [0198.house-robber](./problems/198.house-robber.md) 🆕
- [0198.house-robber](./problems/198.house-robber.md)
- [0203.remove-linked-list-elements](./problems/203.remove-linked-list-elements.md)
- [0206.reverse-linked-list](./problems/206.reverse-linked-list.md)
- [0219.contains-duplicate-ii](./problems/219.contains-duplicate-ii.md)
Expand All @@ -112,7 +114,8 @@ leetcode 题解,记录自己的 leetcode 解题之路。
- [0283.move-zeroes](./problems/283.move-zeroes.md)
- [0342.power-of-four](./problems/342.power-of-four.md) 🆕
- [0349.intersection-of-two-arrays](./problems/349.intersection-of-two-arrays.md)
- [0575.distribute-candies](./problems/575.distribute-candies.md) 🆕
- [0371.sum-of-two-integers](./problems/371.sum-of-two-integers.md) 🆕
- [0575.distribute-candies](./problems/575.distribute-candies.md)


#### 中等难度
Expand All @@ -127,25 +130,27 @@ leetcode 题解,记录自己的 leetcode 解题之路。
- [0040.combination-sum-ii](./problems/40.combination-sum-ii.md)
- [0046.permutations](./problems/46.permutations.md)
- [0047.permutations-ii](./problems/47.permutations-ii.md)
- [0055.jump-game](./problems/55.jump-game.md) 🆕
- [0062.unique-paths](./problems/62.unique-paths.md )🆕
- [0055.jump-game](./problems/55.jump-game.md)
- [0062.unique-paths](./problems/62.unique-paths.md )
- [0073.set-matrix-zeroes](./problems/73.set-matrix-zeroes.md )🆕
- [0075.sort-colors](./problems/75.sort-colors.md)
- [0078.subsets](./problems/78.subsets.md)
- [0086.partition-list](./problems/86.partition-list.md)
- [0090.subsets-ii](./problems/90.subsets-ii.md)
- [0091.decode-ways](./problems/91.decode-ways.md) 🆕
- [0091.decode-ways](./problems/91.decode-ways.md)
- [0092.reverse-linked-list-ii](./problems/92.reverse-linked-list-ii.md)
- [0094.binary-tree-inorder-traversal](./problems/94.binary-tree-inorder-traversal.md)
- [0102.binary-tree-level-order-traversal](./problems/102.binary-tree-level-order-traversal.md)
- [0103.binary-tree-zigzag-level-order-traversal](./problems/103.binary-tree-zigzag-level-order-traversal.md)
- [0139.word-break](./problems/139.word-breakmd)
- [0144.binary-tree-preorder-traversal](./problems/144.binary-tree-preorder-traversal.md)
- [0150.evaluate-reverse-polish-notation](./problems/150.evaluate-reverse-polish-notation.md) 🖊
- [0150.evaluate-reverse-polish-notation](./problems/150.evaluate-reverse-polish-notation.md)
- [0152.maximum-product-subarray](./problems/152.maximum-product-subarray.md) 🆕
- [0199.binary-tree-right-side-view](./problems/199.binary-tree-right-side-view.md)
- [0201.bitwise-and-of-numbers-range](./problems/201.bitwise-and-of-numbers-range.md)
- [0208.implement-trie-prefix-tree](./problems/208.implement-trie-prefix-tree.md)
- [0209.minimum-size-subarray-sum](./problems/209.minimum-size-subarray-sum.md) 🖊
- [0209.minimum-size-subarray-sum](./problems/209.minimum-size-subarray-sum.md)
- [0230.kth-smallest-element-in-a-bst](./problems/230.kth-smallest-element-in-a-bst.md) 🆕
- [0236.lowest-common-ancestor-of-a-binary-tree](./problems/236.lowest-common-ancestor-of-a-binary-tree.md)🆕
- [0238.product-of-array-except-self](./problems/238.product-of-array-except-self.md) 🆕
- [0240.search-a-2-d-matrix-ii](./problems/240.search-a-2-d-matrix-ii.md)
Expand Down
1 change: 1 addition & 0 deletions assets/drawio/155.min-stack.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mxfile modified="2019-05-23T09:51:25.572Z" host="www.draw.io" agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36" etag="RPkBK-kxfKoC4dzgXOxr" version="10.6.8" type="device"><diagram id="PFsNL-FoD6JsyvnQ05nH" name="第 1 页">7Vtbc6M2FP41nrQP3kHiYvMYO077kk47mdlu9k0B2dAFxIKI7f76SiCBQSSbbYiFd8lMYnQkdPnOd46OjpyZuY4Pv2UoDe6Ij6MZNPzDzLyZQbg0AfvLBUchcM1KsMtCvxKBRnAf/ouF0BDSIvRx3mpICYlomLaFHkkS7NGWDGUZ2bebbUnUHjVFO6wI7j0UqdK/Q58GYhVw0ch/x+EukCMDx61qYiQbi5XkAfLJ/kRkbmbmOiOEVk/xYY0jjp3EpXrv9pnaemIZTuhrXvA+fgV/Pc03H7d3hvPwGf2x8sjcqXp5QlEhFjwX+snpUWKQkSLxMe/GmJmrfRBSfJ8ij9fumdKZLKBxxEqAPYoOcUbx4dmZgnr9jDeYxJhmR9ZEvGAZYg6CMxLBfaMAIGXBCfiOkCGh813dcwMLexDIfAdKCwUlY3QgLXWDtFSpBEeHErB0w+SO0eKAa4wMJgAUnMbHJsvUDhO8ANdkudphMi/B6kaAk6XiBLTj1OWTudCOkz1K72R/sFtALQ1LN1BqgDkG/6QA5WgHSo0xuYcy5uz3lzn4lX2UUmMEQRVw4fjw6wk/3+i5fJQHZduBYLMXXdichXbY1HBUAQ0n/jU/SbOSF6E8D702Tmz52fGTwLQsPPACW6so3hxOK2+OorQNo2hNIpKVw5g+wsst7zqnGfmCT2ocb4kft3WNPIdbtVqwrxziO0phCyJF5uFX+HSKsh2m36SaquYTJdo9OpSyDEeIhk/tCfcpVozwJwnZUl4wPte12p1USxXvnWYEOl1BS+nK6nRVgaF0xfiAjifNUt4gf37S1rI70kJQvyFv1WdD5RrZ/89uaUon7E5JqhCcmTRtU7pNwYQkuMNXIUJRuEu4XTC2YSZfcQcReii6FhVx6Pt8mF5f0/ZGQ2xsTndjW0DVw1g95ITv5WCkPxlbWqALFNAfVMKeQ4p+qFR/Mwao1HPKG5EafLO33S5s+vOYUD22XNRujw8h/dSMxkoPciz23AzMC3LcASMEidY3I4SKnroiBMsBHXu1O4R6dYAAFRLXOYqhIwRHGcpsX2i8U4igHlB/7BDBVtw57HHn540R1LNvhPOcW1qAEvbBBnYijv9j1lKL87Xgt2erLUnoPC/vDq9ZA+CkhxItWc+edvwzxiipusUcNJKmDFrmHCIc45iTMeS1eYwiNj4rr8u2BRfu+Rt5QIqIv1GkPqK47km+8WGgeQ7UTTnnfwq+EuZTaJEl9YzjkD8zxnmBXDZPNww0+1EaD5++uF8GzkCbPLS68bbrKLYEzR5jkomx4Y1JTYTsMow4fIPbU2Ub65pVV8ykrlglijn8yWOelo2NAHGCJYTb2nbLr+mhQRoyXjE2Xl2A6YQ0x9G2azdwMpvvNRuwVPb6ngvHM9uNmgkrneRolXISMt/emuznfZRVa0Goyu5J9Z41WjDVpE5OkfdlUpVldb43AzQHdvLLX5NNvWxT+hWlZunkruaHT6/Z1tjyX96Q87QMPd7Qkb0Ctj2z2avGXRm+3ldmX/XP1l0N0R6WicsVXMoeC3uouNhcO5uBzn/Q7PiInu8c1AfC83BPTXtO/rzXn9sysaPNTaj5w8mfl0alXqTp9uhqXmtSVa+qgKVdV2r+a/KAwgN27+n0G5aaX5mU9YyyRmBafd9vmQLbnyCwdXpuW88b2FpqomLi3k/BPVf7ocpSMy8T935M7nUOicA27HcjHys2/7BYXcE3//Vpbv4D</diagram></mxfile>
1 change: 1 addition & 0 deletions assets/drawio/371.sum-of-two-integers.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mxfile modified="2019-05-23T12:35:30.493Z" host="www.draw.io" agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36" etag="nv6lmyas7rovaqpUcTqn" version="10.6.8" type="device"><diagram id="FilWrf6WajoPKxdyopK8" name="第 1 页">7ZxLk5pAFIV/DcupApqHLtXoJItk41SSLSUtUAHaQYxOfn0apVW6nWRSMd5jdBYMXN5fH/EcabDYqNg8VtEi/ShinluuHW8s9s5y3R5z5LApvLQFz9sVkiqLdyXnUJhmP3hbtNvqKov5srNgLUReZ4tucSbKks/qTi2qKrHuLjYXeXeviyjhRmE6i3Kz+iWL67Q9Czc81N/zLEnVnp2gv5tTRGrh9kyWaRSL9VGJjS02qoSod2PFZsTzhp3isltv8src/YFVvKzfssJnPykmT/bz4/PTwFt8+vqQDh4f2q18j/IV7x5t/aIQVGJVxrzZim2x4TrNaj5dRLNm7lq2uayldZHLKUeOttvjVc03rx6osz99KRsuCl5XL3IRtYI6BiWZdnJ94O+3pfQIvapFbYsn+w0foMiRlssfMHIRGYVYjBggIxdMRx4iIzAd+YCMGJiOAkRGYDoKDUYOOSMPTEc9REZgOuobjJjBSJ5t3QWxrCvxjY9ELipZKUUplxzOszzXSlGeJaWcnEk6XNaHDbtMms9BO6PI4rjZzUny3bY5A3y/y77vG+y9E+zdf8VeRQCoC51uTp0+sUIdSAsfolFCNPG6QaWnBGnj4bSEaOR1k0pPCdLKw2kJ0czrRpWeEqSdh9PSWwz9/2pWXZvarZpRwfLHoPznoqzb39pdNa12Z7lsMmHy70yXXFv7mPjmx+SiDaU2DHXJ1WPFnhrZj97XECvoKV1DrKCndA2xgp7SNcQKekrXECvoKZmxAsAww2nJjBX0WtJjBT0lM1a4BiUMW3sG/FqsYA5xrGCmW7XcIG9gx9n3TiMEz6umL8nWzD8st+5+IBeQZ7/ZslHz5VjS/t9uZ7mIyr/bkD9koWP5clV7uirkUMzl4Gkt5PCDbNaEV0u1N0lht8PuQcjy9nxUFVJfv4lN4XgQjM+kQ6fnd4S4v3geCdENLqpEyESgfaf4tkd7tWSIiUDPTfSUIBMBnJYQE4Gem+gpQSYCOC0h3mjQcxM9JcgbDXBauoaeQ/SUbrnvkK9uh1DlJrUzqOud7lYDh1ijHqSnD9EoIXp63a3SU4L09HBaQvT0ululpwTp6eG0hOjpdbdKTwnS08Np6ZY7DwUutVs90XnIDaKiOfndELQtCDsS+aH5kblooykRHTda23T3hjpqqP1tCrKGgkw52vdkeOIGz2UfvURMOXoWpKcEmXLgtISYcvQsSE8JMuXAaQkx5ehZkJ4SZF8mOC1dw50LekpmGrmdLBgy4h5fyi3fY8WvY0XQc4kbyowV+9De9mnrTt1bsNuCvRNdWy/bgpCRR39NiGdekC77vhnEyGO8AIucEmTkgdMSYuQxXoJFTgky8sBpCTHyGC/CIqcEGXngtGRGHnotGS/DoqakjucmHwXqUd/GCE/mjfujQIix6ayPAvW7QuyHphDP9SiQnDy8kXg77+i1zmz8Ew==</diagram></mxfile>
1 change: 1 addition & 0 deletions assets/drawio/73.set-matrix-zeroes.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mxfile modified="2019-05-23T09:51:28.121Z" host="www.draw.io" agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36" etag="u7Zr5KUqWn9R9PeJaYf1" version="10.6.8" type="device"><diagram id="hOtl4ipsQ4CED_UJ3B7D" name="第 1 页">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</diagram></mxfile>
Binary file added assets/problems/155.min-stack-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/problems/155.min-stack-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/problems/155.min-stack-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/problems/371.sum-of-two-integers-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/problems/371.sum-of-two-integers-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/problems/73.set-matrix-zeroes-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/problems/73.set-matrix-zeroes-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion problems/102.binary-tree-level-order-traversal.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ return its level order traversal as:

- 树的基本操作- 遍历 - 层次遍历(BFS)

- 注意塞入null的时候,判断一下当前队列是否为空,不然会无限循环


## 代码

Expand Down Expand Up @@ -121,5 +123,7 @@ var levelOrder = function(root) {

return items;
};

```
## 相关题目
- [103.binary-tree-zigzag-level-order-traversal](./103.binary-tree-zigzag-level-order-traversal.md)
- [104.maximum-depth-of-binary-tree](./104.maximum-depth-of-binary-tree.md)
3 changes: 3 additions & 0 deletions problems/103.binary-tree-zigzag-level-order-traversal.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,7 @@ var zigzagLevelOrder = function(root) {

};
```
## 相关题目
- [102.binary-tree-level-order-traversal](./102.binary-tree-level-order-traversal.md)
- [104.maximum-depth-of-binary-tree](./104.maximum-depth-of-binary-tree.md)

99 changes: 99 additions & 0 deletions problems/104.maximum-depth-of-binary-tree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
## 题目地址

https://leetcode.com/problems/maximum-depth-of-binary-tree/description/

## 题目描述

```
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
Note: A leaf is a node with no children.
Example:
Given binary tree [3,9,20,null,null,15,7],
3
/ \
9 20
/ \
15 7
return its depth = 3.
```

## 思路

由于树是一种递归的数据结构,因此用递归去解决的时候往往非常容易,这道题恰巧也是如此,
用递归实现的代码如下:

```js
var maxDepth = function(root) {
if (!root) return 0;
if (!root.left && !root.right) return 1;
return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));
};
```

如果使用迭代呢? 我们首先应该想到的是树的各种遍历,由于我们求的是深度,因此
使用层次遍历(BFS)是非常合适的。 我们只需要记录有多少层即可。相关思路请查看[binary-tree-traversal](../thinkings/binary-tree-traversal.md)

## 关键点解析

- 队列

- 队列中用 Null(一个特殊元素)来划分每层

- 树的基本操作- 遍历 - 层次遍历(BFS)

## 代码

```js
/*
* @lc app=leetcode id=104 lang=javascript
*
* [104] Maximum Depth of Binary Tree
*/
/**
* Definition for a binary tree node.
* function TreeNode(val) {
* this.val = val;
* this.left = this.right = null;
* }
*/
/**
* @param {TreeNode} root
* @return {number}
*/
var maxDepth = function(root) {
if (!root) return 0;
if (!root.left && !root.right) return 1;

// 层次遍历 BFS
let cur = root;
const queue = [root, null];
let depth = 1;

while ((cur = queue.shift()) !== undefined) {
if (cur === null) {
// 注意⚠️: 不处理会无限循环,进而堆栈溢出
if (queue.length === 0) return depth;
depth++;
queue.push(null);
continue;
}
const l = cur.left;
const r = cur.right;

if (l) queue.push(l);
if (r) queue.push(r);
}

return depth;
};
```
## 相关题目
- [102.binary-tree-level-order-traversal](./102.binary-tree-level-order-traversal.md)
- [103.binary-tree-zigzag-level-order-traversal](./103.binary-tree-zigzag-level-order-traversal.md)
Loading

0 comments on commit b256ae8

Please sign in to comment.