Skip to content

Commit 4262d09

Browse files
Zanger67/leetcodeZanger67/leetcode
Zanger67/leetcode
authored and
Zanger67/leetcode
committed
Updated markdown files
1 parent daeccc0 commit 4262d09

11 files changed

+93
-12
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# **[LeetCode Records](https://leetcode.com/u/Zanger/)** (613 solved)
1+
# **[LeetCode Records](https://leetcode.com/u/Zanger/)** (614 solved)
22

33
<!-- This readme was generated using [WikiLeet](<https://github.com/Zanger67/WikiLeet>) -->
44

@@ -66,6 +66,7 @@ This repo is a collection of my LeetCode solutions, primarily written in Python,
6666
| 36 | [Valid Sudoku](<https://leetcode.com/problems/valid-sudoku>) | Medium | N150 | [solution](<markdowns/_36. Valid Sudoku.md>) | py |
6767
| 39 | [Combination Sum](<https://leetcode.com/problems/combination-sum>) | Medium | B75, N150 | [solution](<markdowns/_39. Combination Sum.md>) | py |
6868
| 40 | [Combination Sum II](<https://leetcode.com/problems/combination-sum-ii>) | Medium | Daily, N150 | [solution](<markdowns/_40. Combination Sum II.md>) | py |
69+
| 42 | [Trapping Rain Water](<https://leetcode.com/problems/trapping-rain-water>) | Hard | N150 | [solution](<markdowns/_42. Trapping Rain Water.md>) | py |
6970
| 46 | [Permutations](<https://leetcode.com/problems/permutations>) | Medium | N150 | [solution](<markdowns/_46. Permutations.md>) | py |
7071
| 48 | [Rotate Image](<https://leetcode.com/problems/rotate-image>) | Medium | B75, N150 | [solution](<markdowns/_48. Rotate Image.md>) | c, py |
7172
| 49 | [Group Anagrams](<https://leetcode.com/problems/group-anagrams>) | Medium | B75, N150 | [solution](<markdowns/_49. Group Anagrams.md>) | py |

markdowns/Hard.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Hard Questions (39)
1+
# Hard Questions (40)
22

33
*[Back to top](<../README.md>)*
44

@@ -8,6 +8,7 @@
88
|-----:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------|:----------|:----------------------------------------------------------------------------------------|:------------|:----------------|
99
| 23 | [Merge k Sorted Lists](<https://leetcode.com/problems/merge-k-sorted-lists>) | Hard | B75, N150 | [solution](<_23. Merge k Sorted Lists.md>) | py | Jun 17, 2024 |
1010
| 25 | [Reverse Nodes in k-Group](<https://leetcode.com/problems/reverse-nodes-in-k-group>) | Hard | N150 | [solution](<_25. Reverse Nodes in k-Group.md>) | c | Jun 07, 2024 |
11+
| 42 | [Trapping Rain Water](<https://leetcode.com/problems/trapping-rain-water>) | Hard | N150 | [solution](<_42. Trapping Rain Water.md>) | py | Mar 11, 2025 |
1112
| 84 | [Largest Rectangle in Histogram](<https://leetcode.com/problems/largest-rectangle-in-histogram>) | Hard | N150 | [solution](<_84. Largest Rectangle in Histogram.md>) | py | Jun 11, 2024 |
1213
| 124 | [Binary Tree Maximum Path Sum](<https://leetcode.com/problems/binary-tree-maximum-path-sum>) | Hard | B75, N150 | [solution](<_124. Binary Tree Maximum Path Sum.md>) | py | Jul 04, 2024 |
1314
| 212 | [Word Search II](<https://leetcode.com/problems/word-search-ii>) | Hard | B75, N150 | [solution](<_212. Word Search II.md>) | py | Jun 27, 2024 |

markdowns/Questions_By_Code_Length.md

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ Calculations are based on the code files's byte sizes.
175175
| 3136 | [Valid Word](<https://leetcode.com/problems/valid-word>) | Easy | | [solution](<_3136. Valid Word.md>) | c, py | Jul 03, 2024 |
176176
| 1101 | [The Earliest Moment When Everyone Become Friends](<https://leetcode.com/problems/the-earliest-moment-when-everyone-become-friends>) | Medium | Weekly Premium | [solution](<_1101. The Earliest Moment When Everyone Become Friends.md>) | py | Jul 04, 2024 |
177177
| 729 | [My Calendar I](<https://leetcode.com/problems/my-calendar-i>) | Medium | Daily | [solution](<_729. My Calendar I.md>) | py | Sep 26, 2024 |
178+
| 42 | [Trapping Rain Water](<https://leetcode.com/problems/trapping-rain-water>) | Hard | N150 | [solution](<_42. Trapping Rain Water.md>) | py | Mar 11, 2025 |
178179
| 2342 | [Max Sum of a Pair With Equal Sum of Digits](<https://leetcode.com/problems/max-sum-of-a-pair-with-equal-sum-of-digits>) | Medium | Daily | [solution](<_2342. Max Sum of a Pair With Equal Sum of Digits.md>) | py | Feb 12, 2025 |
179180
| 2743 | [Count Substrings Without Repeating Character](<https://leetcode.com/problems/count-substrings-without-repeating-character>) | Medium | Weekly Premium | [solution](<_2743. Count Substrings Without Repeating Character.md>) | java, py | Jun 22, 2024 |
180181
| 1653 | [Minimum Deletions to Make String Balanced](<https://leetcode.com/problems/minimum-deletions-to-make-string-balanced>) | Medium | Daily | [solution](<_1653. Minimum Deletions to Make String Balanced.md>) | py | Jul 30, 2024 |

markdowns/Questions_By_Recent.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Calculations are based on the date of the first solve.
66

77
| # | Title | Level | Cats | Solution | Languages | Date Complete |
88
|-----:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------|:--------------------------|:----------------------------------------------------------------------------------------------------|:--------------------------------------------|:----------------|
9+
| 42 | [Trapping Rain Water](<https://leetcode.com/problems/trapping-rain-water>) | Hard | N150 | [solution](<_42. Trapping Rain Water.md>) | py | Mar 11, 2025 |
910
| 2063 | [Vowels of All Substrings](<https://leetcode.com/problems/vowels-of-all-substrings>) | Medium | | [solution](<_2063. Vowels of All Substrings.md>) | py | Mar 11, 2025 |
1011
| 1358 | [Number of Substrings Containing All Three Characters](<https://leetcode.com/problems/number-of-substrings-containing-all-three-characters>) | Medium | | [solution](<_1358. Number of Substrings Containing All Three Characters.md>) | py | Mar 11, 2025 |
1112
| 1100 | [Find K-Length Substrings With No Repeated Characters](<https://leetcode.com/problems/find-k-length-substrings-with-no-repeated-characters>) | Medium | Weekly Premium | [solution](<_1100. Find K-Length Substrings With No Repeated Characters.md>) | py | Mar 10, 2025 |

markdowns/Topics.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
------
66

7-
- [Array](<by_topic/Array.md>) (300 completed)
7+
- [Array](<by_topic/Array.md>) (301 completed)
88
- [String](<by_topic/String.md>) (144 completed)
99
- [Hash Table](<by_topic/Hash Table.md>) (137 completed)
1010
- [Depth-First Search](<by_topic/Depth-First Search.md>) (103 completed)
@@ -13,9 +13,9 @@
1313
- [Math](<by_topic/Math.md>) (79 completed)
1414
- [Sorting](<by_topic/Sorting.md>) (74 completed)
1515
- [Breadth-First Search](<by_topic/Breadth-First Search.md>) (71 completed)
16-
- [Two Pointers](<by_topic/Two Pointers.md>) (59 completed)
17-
- [Stack](<by_topic/Stack.md>) (55 completed)
18-
- [Dynamic Programming](<by_topic/Dynamic Programming.md>) (54 completed)
16+
- [Two Pointers](<by_topic/Two Pointers.md>) (60 completed)
17+
- [Stack](<by_topic/Stack.md>) (56 completed)
18+
- [Dynamic Programming](<by_topic/Dynamic Programming.md>) (55 completed)
1919
- [Matrix](<by_topic/Matrix.md>) (53 completed)
2020
- [Greedy](<by_topic/Greedy.md>) (48 completed)
2121
- [Linked List](<by_topic/Linked List.md>) (45 completed)
@@ -35,7 +35,7 @@
3535
- [Binary Search Tree](<by_topic/Binary Search Tree.md>) (16 completed)
3636
- [Union Find](<by_topic/Union Find.md>) (16 completed)
3737
- [Queue](<by_topic/Queue.md>) (14 completed)
38-
- [Monotonic Stack](<by_topic/Monotonic Stack.md>) (11 completed)
38+
- [Monotonic Stack](<by_topic/Monotonic Stack.md>) (12 completed)
3939
- [Divide and Conquer](<by_topic/Divide and Conquer.md>) (8 completed)
4040
- [String Matching](<by_topic/String Matching.md>) (8 completed)
4141
- [Shortest Path](<by_topic/Shortest Path.md>) (7 completed)

markdowns/_42. Trapping Rain Water.md

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# 42. [Trapping Rain Water](<https://leetcode.com/problems/trapping-rain-water>)
2+
3+
*All prompts are owned by LeetCode. To view the prompt, click the title link above.*
4+
5+
*[Back to top](<../README.md>)*
6+
7+
------
8+
9+
> *First completed : March 11, 2025*
10+
>
11+
> *Last updated : March 11, 2025*
12+
13+
------
14+
15+
> **Related Topics** : **[Array](<by_topic/Array.md>), [Two Pointers](<by_topic/Two Pointers.md>), [Dynamic Programming](<by_topic/Dynamic Programming.md>), [Stack](<by_topic/Stack.md>), [Monotonic Stack](<by_topic/Monotonic Stack.md>)**
16+
>
17+
> **Acceptance Rate** : **64.3 %**
18+
19+
------
20+
21+
## Solutions
22+
23+
- [h42 v1 heap.py](<../my-submissions/h42 v1 heap.py>)
24+
- [h42 v2 two pointer.py](<../my-submissions/h42 v2 two pointer.py>)
25+
### Python
26+
#### [h42 v1 heap.py](<../my-submissions/h42 v1 heap.py>)
27+
```Python
28+
class Solution:
29+
def trap(self, height: List[int]) -> int:
30+
output = 0
31+
32+
vals = [(-x, i) for i, x in enumerate(height)]
33+
heapify(vals)
34+
35+
left_max = right_max = heappop(vals)[1]
36+
while vals and (left_max > 0 or right_max < len(height) - 1):
37+
val, i = heappop(vals)
38+
val = -val
39+
40+
if left_max <= i <= right_max :
41+
continue
42+
43+
if i <= left_max :
44+
minn = min(val, height[left_max])
45+
output += sum(minn - x for x in height[i + 1:left_max])
46+
left_max = i
47+
else :
48+
minn = min(val, height[right_max])
49+
output += sum(minn - x for x in height[right_max + 1:i])
50+
right_max = i
51+
52+
return output
53+
```
54+
55+
#### [h42 v2 two pointer.py](<../my-submissions/h42 v2 two pointer.py>)
56+
```Python
57+
class Solution:
58+
def trap(self, height: List[int]) -> int:
59+
left_max = right_max = output = 0
60+
left, right = 0, len(height) - 1
61+
62+
while left < right :
63+
if height[left] < height[right] :
64+
output += (left_max := max(left_max, height[left])) - height[left]
65+
left += 1
66+
else :
67+
output += (right_max := max(right_max, height[right])) - height[right]
68+
right -= 1
69+
70+
return output
71+
```
72+

markdowns/by_topic/Array.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [Array](<https://leetcode.com/tag/Array/>) (300 completed)
1+
# [Array](<https://leetcode.com/tag/Array/>) (301 completed)
22

33
*[Back to top](<../../README.md>)*
44

@@ -13,6 +13,7 @@
1313
| 36 | [Valid Sudoku](<https://leetcode.com/problems/valid-sudoku>) | Medium | N150 | [solution](<../_36. Valid Sudoku.md>) | py | Jun 13, 2024 |
1414
| 39 | [Combination Sum](<https://leetcode.com/problems/combination-sum>) | Medium | B75, N150 | [solution](<../_39. Combination Sum.md>) | py | Jul 16, 2024 |
1515
| 40 | [Combination Sum II](<https://leetcode.com/problems/combination-sum-ii>) | Medium | Daily, N150 | [solution](<../_40. Combination Sum II.md>) | py | Aug 13, 2024 |
16+
| 42 | [Trapping Rain Water](<https://leetcode.com/problems/trapping-rain-water>) | Hard | N150 | [solution](<../_42. Trapping Rain Water.md>) | py | Mar 11, 2025 |
1617
| 46 | [Permutations](<https://leetcode.com/problems/permutations>) | Medium | N150 | [solution](<../_46. Permutations.md>) | py | Jun 07, 2024 |
1718
| 48 | [Rotate Image](<https://leetcode.com/problems/rotate-image>) | Medium | B75, N150 | [solution](<../_48. Rotate Image.md>) | c, py | Jun 15, 2024 |
1819
| 49 | [Group Anagrams](<https://leetcode.com/problems/group-anagrams>) | Medium | B75, N150 | [solution](<../_49. Group Anagrams.md>) | py | Jun 13, 2024 |

0 commit comments

Comments
 (0)