Skip to content

Commit 3c4fa91

Browse files
committed
2 parents 5b9b961 + 5b6bd73 commit 3c4fa91

File tree

4 files changed

+135
-0
lines changed

4 files changed

+135
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* function TreeNode(val, left, right) {
4+
* this.val = (val===undefined ? 0 : val)
5+
* this.left = (left===undefined ? null : left)
6+
* this.right = (right===undefined ? null : right)
7+
* }
8+
*/
9+
/**
10+
* @param {TreeNode} root
11+
* @return {number}
12+
*/
13+
var maxDepth = function(root) {
14+
15+
return dfs(root,1)
16+
17+
function dfs(node, cnt){
18+
if(!node) return 0;
19+
20+
let left, right;
21+
if(node.left) left = dfs(node.left,cnt+1);
22+
if(node.right) right = dfs(node.right,cnt+1);
23+
if(node.left == null && node.right == null) {
24+
return cnt;
25+
}
26+
return Math.max(left ?? 0,right ?? 0);
27+
}
28+
29+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<h2><a href="https://leetcode.com/problems/maximum-depth-of-binary-tree">104. Maximum Depth of Binary Tree</a></h2><h3>Easy</h3><hr><p>Given the <code>root</code> of a binary tree, return <em>its maximum depth</em>.</p>
2+
3+
<p>A binary tree&#39;s <strong>maximum depth</strong>&nbsp;is the number of nodes along the longest path from the root node down to the farthest leaf node.</p>
4+
5+
<p>&nbsp;</p>
6+
<p><strong class="example">Example 1:</strong></p>
7+
<img alt="" src="https://assets.leetcode.com/uploads/2020/11/26/tmp-tree.jpg" style="width: 400px; height: 277px;" />
8+
<pre>
9+
<strong>Input:</strong> root = [3,9,20,null,null,15,7]
10+
<strong>Output:</strong> 3
11+
</pre>
12+
13+
<p><strong class="example">Example 2:</strong></p>
14+
15+
<pre>
16+
<strong>Input:</strong> root = [1,null,2]
17+
<strong>Output:</strong> 2
18+
</pre>
19+
20+
<p>&nbsp;</p>
21+
<p><strong>Constraints:</strong></p>
22+
23+
<ul>
24+
<li>The number of nodes in the tree is in the range <code>[0, 10<sup>4</sup>]</code>.</li>
25+
<li><code>-100 &lt;= Node.val &lt;= 100</code></li>
26+
</ul>

공예영/3주차/README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
A collection of LeetCode questions to ace the coding interview! - Created using [LeetHub v2](https://github.com/arunbhardwaj/LeetHub-2.0)
2+
<!---LeetCode Topics Start-->
3+
# LeetCode Topics
4+
## Array
5+
| |
6+
| ------- |
7+
| [0001-two-sum](https://github.com/yeyounging/Algorithm/tree/master/0001-two-sum) |
8+
| [0049-group-anagrams](https://github.com/yeyounging/Algorithm/tree/master/0049-group-anagrams) |
9+
| [0121-best-time-to-buy-and-sell-stock](https://github.com/yeyounging/Algorithm/tree/master/0121-best-time-to-buy-and-sell-stock) |
10+
| [0704-binary-search](https://github.com/yeyounging/Algorithm/tree/master/0704-binary-search) |
11+
## Hash Table
12+
| |
13+
| ------- |
14+
| [0001-two-sum](https://github.com/yeyounging/Algorithm/tree/master/0001-two-sum) |
15+
| [0013-roman-to-integer](https://github.com/yeyounging/Algorithm/tree/master/0013-roman-to-integer) |
16+
| [0049-group-anagrams](https://github.com/yeyounging/Algorithm/tree/master/0049-group-anagrams) |
17+
| [0242-valid-anagram](https://github.com/yeyounging/Algorithm/tree/master/0242-valid-anagram) |
18+
## String
19+
| |
20+
| ------- |
21+
| [0013-roman-to-integer](https://github.com/yeyounging/Algorithm/tree/master/0013-roman-to-integer) |
22+
| [0020-valid-parentheses](https://github.com/yeyounging/Algorithm/tree/master/0020-valid-parentheses) |
23+
| [0049-group-anagrams](https://github.com/yeyounging/Algorithm/tree/master/0049-group-anagrams) |
24+
| [0125-valid-palindrome](https://github.com/yeyounging/Algorithm/tree/master/0125-valid-palindrome) |
25+
| [0242-valid-anagram](https://github.com/yeyounging/Algorithm/tree/master/0242-valid-anagram) |
26+
## Sorting
27+
| |
28+
| ------- |
29+
| [0049-group-anagrams](https://github.com/yeyounging/Algorithm/tree/master/0049-group-anagrams) |
30+
| [0242-valid-anagram](https://github.com/yeyounging/Algorithm/tree/master/0242-valid-anagram) |
31+
## Two Pointers
32+
| |
33+
| ------- |
34+
| [0125-valid-palindrome](https://github.com/yeyounging/Algorithm/tree/master/0125-valid-palindrome) |
35+
## Dynamic Programming
36+
| |
37+
| ------- |
38+
| [0121-best-time-to-buy-and-sell-stock](https://github.com/yeyounging/Algorithm/tree/master/0121-best-time-to-buy-and-sell-stock) |
39+
## Stack
40+
| |
41+
| ------- |
42+
| [0020-valid-parentheses](https://github.com/yeyounging/Algorithm/tree/master/0020-valid-parentheses) |
43+
## Binary Search
44+
| |
45+
| ------- |
46+
| [0704-binary-search](https://github.com/yeyounging/Algorithm/tree/master/0704-binary-search) |
47+
## Linked List
48+
| |
49+
| ------- |
50+
| [0206-reverse-linked-list](https://github.com/yeyounging/Algorithm/tree/master/0206-reverse-linked-list) |
51+
## Recursion
52+
| |
53+
| ------- |
54+
| [0206-reverse-linked-list](https://github.com/yeyounging/Algorithm/tree/master/0206-reverse-linked-list) |
55+
## Tree
56+
| |
57+
| ------- |
58+
| [0104-maximum-depth-of-binary-tree](https://github.com/yeyounging/Algorithm/tree/master/0104-maximum-depth-of-binary-tree) |
59+
| [0226-invert-binary-tree](https://github.com/yeyounging/Algorithm/tree/master/0226-invert-binary-tree) |
60+
## Depth-First Search
61+
| |
62+
| ------- |
63+
| [0104-maximum-depth-of-binary-tree](https://github.com/yeyounging/Algorithm/tree/master/0104-maximum-depth-of-binary-tree) |
64+
| [0226-invert-binary-tree](https://github.com/yeyounging/Algorithm/tree/master/0226-invert-binary-tree) |
65+
## Breadth-First Search
66+
| |
67+
| ------- |
68+
| [0104-maximum-depth-of-binary-tree](https://github.com/yeyounging/Algorithm/tree/master/0104-maximum-depth-of-binary-tree) |
69+
| [0226-invert-binary-tree](https://github.com/yeyounging/Algorithm/tree/master/0226-invert-binary-tree) |
70+
## Binary Tree
71+
| |
72+
| ------- |
73+
| [0104-maximum-depth-of-binary-tree](https://github.com/yeyounging/Algorithm/tree/master/0104-maximum-depth-of-binary-tree) |
74+
| [0226-invert-binary-tree](https://github.com/yeyounging/Algorithm/tree/master/0226-invert-binary-tree) |
75+
## Math
76+
| |
77+
| ------- |
78+
| [0013-roman-to-integer](https://github.com/yeyounging/Algorithm/tree/master/0013-roman-to-integer) |
79+
<!---LeetCode Topics End-->

공예영/3주차/stats.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"leetcode":{"easy":10,"hard":0,"medium":0,"shas":{"0049-group-anagrams":{"0049-group-anagrams.js":"48927907c04dffe0aaa8d5300dd7a15b5b76002c","README.md":"9d4e57a1660ecf3ab6088a2b5784c68ccf5ddbcf"},"0242-valid-anagram":{"0242-valid-anagram.js":"2cb03db0629a185b8fcc63d4ac1315130c302773","README.md":"7216cfc7074105cd2f2a50ce61da29ee3295b549","difficulty":"easy"},"README.md":{"":"8e2b7f2de1351a6110771053cfa9009a54f7f11c"},"0001-two-sum":{"0001-two-sum.js":"4ff2c10093539526fefae671abf451ea6cf47ee3","README.md":"295832280eacc9b202138f15adc074a9cb24c66f","difficulty":"easy"},"0125-valid-palindrome":{"0125-valid-palindrome.js":"cff7bfcbd7d788aaa9cd3d151b42e72637a1dc88","README.md":"213d38e6bd9704d91b8759c7b29ebd97622cca49","difficulty":"easy"},"stats.json":{"":"a15cba2522870cba69b0bc429eaa7a6f4a2ea439"},"0121-best-time-to-buy-and-sell-stock":{"0121-best-time-to-buy-and-sell-stock.js":"3ad0e8a62b7e7d8fc92d273d1fbba401941e5d90","README.md":"c985d4a7bb22bad48ddd48f971d6376a9b0b8e9b","difficulty":"easy"},"0020-valid-parentheses":{"0020-valid-parentheses.js":"93bc3b2cb6ac33286ac93bec52ff7e943fce8c99","README.md":"ead2a7774ca440d1a8f0d408fe3c05c8d18fff0b","difficulty":"easy"},"0704-binary-search":{"0704-binary-search.js":"ab3702c95bacb274a530e113477c1e48f26d6ee5","README.md":"a07059ea4eb30614e3cf86f7c5477c501209ddda","difficulty":"easy"},"0206-reverse-linked-list":{"0206-reverse-linked-list.js":"ec660f4c3b0ed46e637b58dadebff39ff92f4ea9","README.md":"d0e5a229257a811c50c7bcd689b492fe0a4082d2","difficulty":"easy"},"0226-invert-binary-tree":{"0226-invert-binary-tree.js":"b05af2c1de5d17aacac06de91b7db3929bb40038","README.md":"b2226c1562ee22db45da1202e92de55812ebe3e6","difficulty":"easy"},"0013-roman-to-integer":{"README.md":"0cff3a12e3a57725016019dffbd00e1453cced47","difficulty":"easy"},"0104-maximum-depth-of-binary-tree":{"0104-maximum-depth-of-binary-tree.js":"e04bd86ad16e7472bef2e704216fda93cf0e9759","README.md":"3e88d40eac7067a0b69cceb90c76020b6f152ae0","difficulty":"easy"}},"solved":10}}

0 commit comments

Comments
 (0)