Skip to content

Commit 3c5518a

Browse files
updating docs
1 parent a2db159 commit 3c5518a

14 files changed

+1155
-63
lines changed

docs/.vitepress/Sidebar.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ export default Sidebar = [
159159
text: "108 - Convert Sorted Array to Binary Search Tree",
160160
link: "/solution/0101-0200/108 - Convert Sorted Array to Binary Search Tree.md",
161161
},
162+
{
163+
text: "109 - Convert Sorted List to Binary Search Tree",
164+
link: "/solution/0101-0200/109 - Convert Sorted List to Binary Search Tree.md",
165+
},
162166
{
163167
text: "110 - Balanced Binary Tree",
164168
link: "/solution/0101-0200/110 - Balanced Binary Tree.md",
@@ -191,6 +195,10 @@ export default Sidebar = [
191195
text: "125 - Valid Palindrome",
192196
link: "/solution/0101-0200/125 - Valid Palindrome.md",
193197
},
198+
{
199+
text: "129 - Sum Root to Leaf Numbers",
200+
link: "/solution/0101-0200/129 - Sum Root to Leaf Numbers.md",
201+
},
194202
{
195203
text: "136 - Single Number",
196204
link: "/solution/0101-0200/136 - Single Number.md",
@@ -199,6 +207,10 @@ export default Sidebar = [
199207
text: "141 - Linked List Cycle",
200208
link: "/solution/0101-0200/141 - Linked List Cycle.md",
201209
},
210+
{
211+
text: "142 - Linked List Cycle II",
212+
link: "/solution/0101-0200/142 - Linked List Cycle II.md",
213+
},
202214
{
203215
text: "144 - Binary Tree Preorder Traversal",
204216
link: "/solution/0101-0200/144 - Binary Tree Preorder Traversal.md",
@@ -405,6 +417,10 @@ export default Sidebar = [
405417
text: "374 - Guess Number Higher or Lower",
406418
link: "/solution/0301-0400/374 - Guess Number Higher or Lower.md",
407419
},
420+
{
421+
text: "382 - Linked List Random Node",
422+
link: "/solution/0301-0400/382 - Linked List Random Node.md",
423+
},
408424
{
409425
text: "383 - Ransom Note",
410426
link: "/solution/0301-0400/383 - Ransom Note.md",
@@ -558,6 +574,10 @@ export default Sidebar = [
558574
text: "653 - Two Sum IV - Input is a BST",
559575
link: "/solution/0601-0700/653 - Two Sum IV - Input is a BST.md",
560576
},
577+
{
578+
text: "695 - Max Area of Island",
579+
link: "/solution/0601-0700/695 - Max Area of Island.md",
580+
},
561581
],
562582
},
563583
{
@@ -588,6 +608,10 @@ export default Sidebar = [
588608
collapsible: true,
589609
collapsed: true,
590610
items: [
611+
{
612+
text: "875 - Koko Eating Bananas",
613+
link: "/solution/0801-0900/875 - Koko Eating Bananas.md",
614+
},
591615
{
592616
text: "876 - Middle of the Linked List",
593617
link: "/solution/0801-0900/876 - Middle of the Linked List.md",
@@ -662,6 +686,17 @@ export default Sidebar = [
662686
},
663687
],
664688
},
689+
{
690+
text: "1301-1400",
691+
collapsible: true,
692+
collapsed: true,
693+
items: [
694+
{
695+
text: "1345 - Jump Game IV",
696+
link: "/solution/1301-1400/1345 - Jump Game IV.md",
697+
},
698+
],
699+
},
665700
{
666701
text: "1401-1500",
667702
collapsible: true,
@@ -706,6 +741,10 @@ export default Sidebar = [
706741
text: "1537 - Get the Maximum Score",
707742
link: "/solution/1501-1600/1537 - Get the Maximum Score.md",
708743
},
744+
{
745+
text: "1539 - Kth Missing Positive Number",
746+
link: "/solution/1501-1600/1539 - Kth Missing Positive Number.md",
747+
},
709748
],
710749
},
711750
{
@@ -755,10 +794,18 @@ export default Sidebar = [
755794
text: "2114 - Maximum Number of Words Found in Sentences",
756795
link: "/solution/2101-2200/2114 - Maximum Number of Words Found in Sentences.md",
757796
},
797+
{
798+
text: "2160 - Minimum Sum of Four Digit Number After Splitting Digits",
799+
link: "/solution/2101-2200/2160 - Minimum Sum of Four Digit Number After Splitting Digits.md",
800+
},
758801
{
759802
text: "2176 - Count Equal and Divisible Pairs in an Array",
760803
link: "/solution/2101-2200/2176 - Count Equal and Divisible Pairs in an Array.md",
761804
},
805+
{
806+
text: "2187 - Minimum Time to Complete Trips",
807+
link: "/solution/2101-2200/2187 - Minimum Time to Complete Trips.md",
808+
},
762809
{
763810
text: "2413 - Smallest Even Multiple",
764811
link: "/solution/2101-2200/2413 - Smallest Even Multiple.md",

docs/SERIALWISE.md

Lines changed: 20 additions & 0 deletions
Large diffs are not rendered by default.

docs/TOPICWISE.md

Lines changed: 101 additions & 63 deletions
Large diffs are not rendered by default.

docs/solution/0101-0200/101 - Symmetric Tree.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,27 @@ func isMirror(t1, t2 *TreeNode) bool {
6363

6464
```
6565

66+
```py [Python]
67+
68+
from out.definitions.treenode import TreeNode
69+
70+
71+
class Solution:
72+
def isSymmetric(self, root: TreeNode) -> bool:
73+
return self._is_mirror(root, root)
74+
75+
def _is_mirror(self, t1: TreeNode, t2: TreeNode) -> bool:
76+
if not t1 and not t2:
77+
return True
78+
if not t1 or not t2:
79+
return False
80+
81+
return ((t1.val == t2.val) and
82+
self._is_mirror(t1.right, t2.left) and
83+
self._is_mirror(t1.left, t2.right))
84+
85+
```
86+
6687
:::
6788

6889
### [_..._](#)
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# 109. Convert Sorted List to Binary Search Tree [![share]](https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/)
2+
3+
![][medium]
4+
5+
## Problem Statement
6+
7+
<p>Given the <code>head</code> of a singly linked list where elements are sorted in <strong>ascending order</strong>, convert <em>it to a </em><span data-keyword="height-balanced"><strong><em>height-balanced</em></strong></span> <em>binary search tree</em>.</p>
8+
<p> </p>
9+
<p><strong class="example">Example 1:</strong></p>
10+
<img alt="" src="https://assets.leetcode.com/uploads/2020/08/17/linked.jpg" style="width: 500px; height: 388px;"/>
11+
12+
```
13+
Input: head = [-10,-3,0,5,9]
14+
Output: [0,-3,9,-10,null,5]
15+
Explanation: One possible answer is [0,-3,9,-10,null,5], which represents the shown height balanced BST.
16+
```
17+
18+
<p><strong class="example">Example 2:</strong></p>
19+
20+
```
21+
Input: head = []
22+
Output: []
23+
```
24+
25+
<p> </p>
26+
<p><strong>Constraints:</strong></p>
27+
<ul>
28+
<li>The number of nodes in <code>head</code> is in the range <code>[0, 2 * 10<sup>4</sup>]</code>.</li>
29+
<li><code>-10<sup>5</sup> &lt;= Node.val &lt;= 10<sup>5</sup></code></li>
30+
</ul>
31+
32+
## Solution:
33+
34+
::: code-group
35+
36+
```go [Go]
37+
package main
38+
39+
// Definition for singly-linked list.
40+
type ListNode struct {
41+
Val int
42+
Next *ListNode
43+
}
44+
45+
// Definition for a binary tree node.
46+
type TreeNode struct {
47+
Val int
48+
Left *TreeNode
49+
Right *TreeNode
50+
}
51+
52+
func sortedListToBST(head *ListNode) *TreeNode {
53+
if head == nil {
54+
return nil
55+
}
56+
57+
if head.Next == nil {
58+
return &TreeNode{Val: head.Val}
59+
}
60+
61+
slow, fast := head, head
62+
prev := slow
63+
64+
for fast != nil && fast.Next != nil {
65+
prev = slow
66+
slow = slow.Next
67+
fast = fast.Next.Next
68+
}
69+
70+
// slow points to the root of the current subtree
71+
72+
// break the link between the left subtree and the root
73+
prev.Next = nil
74+
75+
root := &TreeNode{Val: slow.Val}
76+
root.Left = sortedListToBST(head)
77+
root.Right = sortedListToBST(slow.Next)
78+
79+
return root
80+
}
81+
82+
```
83+
84+
:::
85+
86+
### [_..._](#)
87+
88+
```
89+
90+
```
91+
92+
<!----------------------------------{ link }--------------------------------->
93+
94+
[share]: https://graph.org/file/3ea5234dda646b71c574a.png
95+
[easy]: https://img.shields.io/badge/Difficulty-Easy-bright.svg
96+
[medium]: https://img.shields.io/badge/Difficulty-Medium-yellow.svg
97+
[hard]: https://img.shields.io/badge/Difficulty-Hard-red.svg
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# 129. Sum Root to Leaf Numbers [![share]](https://leetcode.com/problems/sum-root-to-leaf-numbers/)
2+
3+
![][medium]
4+
5+
## Problem Statement
6+
7+
<p>You are given the <code>root</code> of a binary tree containing digits from <code>0</code> to <code>9</code> only.</p>
8+
<p>Each root-to-leaf path in the tree represents a number.</p>
9+
<ul>
10+
<li>For example, the root-to-leaf path <code>1 -&gt; 2 -&gt; 3</code> represents the number <code>123</code>.</li>
11+
</ul>
12+
<p>Return <em>the total sum of all root-to-leaf numbers</em>. Test cases are generated so that the answer will fit in a <strong>32-bit</strong> integer.</p>
13+
<p>A <strong>leaf</strong> node is a node with no children.</p>
14+
<p> </p>
15+
<p><strong class="example">Example 1:</strong></p>
16+
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/num1tree.jpg" style="width: 212px; height: 182px;"/>
17+
18+
```
19+
Input: root = [1,2,3]
20+
Output: 25
21+
Explanation:
22+
The root-to-leaf path 1-&gt;2 represents the number 12.
23+
The root-to-leaf path 1-&gt;3 represents the number 13.
24+
Therefore, sum = 12 + 13 = 25.
25+
```
26+
27+
<p><strong class="example">Example 2:</strong></p>
28+
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/num2tree.jpg" style="width: 292px; height: 302px;"/>
29+
30+
```
31+
Input: root = [4,9,0,5,1]
32+
Output: 1026
33+
Explanation:
34+
The root-to-leaf path 4-&gt;9-&gt;5 represents the number 495.
35+
The root-to-leaf path 4-&gt;9-&gt;1 represents the number 491.
36+
The root-to-leaf path 4-&gt;0 represents the number 40.
37+
Therefore, sum = 495 + 491 + 40 = 1026.
38+
```
39+
40+
<p> </p>
41+
<p><strong>Constraints:</strong></p>
42+
<ul>
43+
<li>The number of nodes in the tree is in the range <code>[1, 1000]</code>.</li>
44+
<li><code>0 &lt;= Node.val &lt;= 9</code></li>
45+
<li>The depth of the tree will not exceed <code>10</code>.</li>
46+
</ul>
47+
48+
## Solution:
49+
50+
::: code-group
51+
52+
```go [Go]
53+
package main
54+
55+
// Definition for a binary tree node.
56+
type TreeNode struct {
57+
Val int
58+
Left *TreeNode
59+
Right *TreeNode
60+
}
61+
62+
func sumNumbers(root *TreeNode) int {
63+
return dfs(root, 0)
64+
}
65+
66+
func dfs(root *TreeNode, num int) int {
67+
if root == nil {
68+
return 0
69+
}
70+
71+
num = num*10 + root.Val
72+
if root.Left == nil && root.Right == nil {
73+
return num
74+
}
75+
76+
return dfs(root.Left, num) + dfs(root.Right, num)
77+
}
78+
79+
```
80+
81+
:::
82+
83+
### [_..._](#)
84+
85+
```
86+
87+
```
88+
89+
<!----------------------------------{ link }--------------------------------->
90+
91+
[share]: https://graph.org/file/3ea5234dda646b71c574a.png
92+
[easy]: https://img.shields.io/badge/Difficulty-Easy-bright.svg
93+
[medium]: https://img.shields.io/badge/Difficulty-Medium-yellow.svg
94+
[hard]: https://img.shields.io/badge/Difficulty-Hard-red.svg

0 commit comments

Comments
 (0)