Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a86aa08

Browse files
resolved README merge conflict
2 parents eb9c5c2 + a393c53 commit a86aa08

File tree

6 files changed

+147
-0
lines changed

6 files changed

+147
-0
lines changed

‎Hard/RegexMatching/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Regular Expression Matching
2+
3+
[Leetcode Link](https://leetcode.com/problems/regular-expression-matching/)
4+
5+
## Problem:
6+
7+
Given an input string (`s`) and a pattern (`p`), implement regular expression matching with support for `'.'` and `'*'` where:
8+
9+
- `'.'` Matches any single character.​​​​
10+
- `'*'` Matches zero or more of the preceding element.
11+
The matching should cover the _entire_ input string (not partial).
12+
13+
## Example:
14+
15+
```
16+
Input: s = "aa", p = "a"
17+
Output: false
18+
Explanation: "a" does not match the entire string "aa".
19+
```
20+
21+
```
22+
Input: s = "aa", p = "a*"
23+
Output: true
24+
Explanation: '*' means zero or more of the preceding element, 'a'. Therefore, by repeating 'a' once, it becomes "aa".
25+
```
26+
27+
```
28+
Input: s = "ab", p = ".*"
29+
Output: true
30+
Explanation: ".*" means "zero or more (*) of any character (.)".
31+
```
32+
33+
```
34+
Input: s = "mississippi", p = "mis*is*p*."
35+
Output: false
36+
```
37+
38+
## Note:
39+
40+
- 0 <= s.length <= 20
41+
- 0 <= p.length <= 30
42+
- s contains only lowercase English letters.
43+
- p contains only lowercase English letters, '.', and '\*'.
44+
- It is guaranteed for each appearance of the character '\*', there will be a previous valid character to match.

‎Hard/RegexMatching/solution.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class Solution:
2+
def isMatch(self, s: str, p: str) -> bool:
3+
dp = [[False for c in range(len(p)+1)] for c in range(len(s)+1)]
4+
dp[-1][-1] = True
5+
for j in range(len(p)-1, -1, -1):
6+
if j+1 < len(p) and p[j+1] == "*":
7+
dp[-1][j] = dp[-1][j+2]
8+
for i in range(len(s)-1, -1, -1):
9+
for j in range(len(p)-1, -1, -1):
10+
if p[j] == "*":
11+
continue
12+
isMatching = p[j] == s[i] or p[j] == "."
13+
if j+1 < len(p) and p[j+1] == "*":
14+
dp[i][j] = dp[i][j+2] or (isMatching and dp[i+1][j])
15+
else:
16+
dp[i][j] = isMatching and dp[i+1][j+1]
17+
return dp[0][0]
18+
19+
20+
sol = Solution()
21+
s = "aaa"
22+
p = "ab*a"
23+
print(sol.isMatch(s, p))
24+
25+
s = "aab"
26+
p = "c*a*b"
27+
print(sol.isMatch(s, p))
28+
29+
s = "mississippi"
30+
p = "mis*is*p*."
31+
print(sol.isMatch(s, p))

‎Medium/ContainerWithMostWater/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Container With Most Water
2+
3+
[Leetcode Link](https://leetcode.com/problems/container-with-most-water/)
4+
5+
## Problem:
6+
7+
Given n non-negative integers `a1, a2, ..., an` , where each represents a point at coordinate `(i, ai)`. n vertical lines are drawn such that the two endpoints of the line `i` is at `(i, ai)` and `(i, 0)`. Find two lines, which, together with the x-axis forms a container, such that the container contains the most water.
8+
9+
_Notice_ that you may not slant the container.
10+
11+
## Example:
12+
13+
![example](asset/question_11.jpg)
14+
15+
```
16+
Input: height = [1,8,6,2,5,4,8,3,7]
17+
Output: 49
18+
Explanation: The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.
19+
```
20+
21+
```
22+
Input: height = [4,3,2,1,4]
23+
Output: 16
24+
```
25+
26+
## Note:
17.9 KB
Loading[フレーム]
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from typing import List
2+
3+
# Recursively find all combinations (ie. brute force) is not efficient
4+
5+
6+
class Solution:
7+
def maxArea(self, height: List[int]) -> int:
8+
9+
# recursively find all combinations
10+
# def combinationOfTwo(arr, start=0, comb=[]):
11+
# if len(comb) == 2:
12+
# combinations.append(list(comb))
13+
# return
14+
# for i in range(start, len(arr)):
15+
# comb.append(i)
16+
# combinationOfTwo(arr, i+1, comb)
17+
# comb.pop()
18+
19+
# find height given two indices for containers
20+
def waterContainer(arr, left, right):
21+
height = min(arr[left], arr[right])
22+
width = right-left
23+
return height*width
24+
25+
# combinations = list()
26+
result = 0
27+
# combinationOfTwo(height)
28+
# for left, right in combinations:
29+
# result = max(result, waterContainer(height, left, right))
30+
31+
left = 0
32+
right = len(height)-1
33+
while left < right:
34+
result = max(result, waterContainer(height, left, right))
35+
if height[left] < height[right]:
36+
left += 1
37+
elif height[left] >= height[right]:
38+
right -= 1
39+
return result
40+
41+
42+
sol = Solution()
43+
height = [1, 8, 6, 2, 5, 4, 8, 3, 7]
44+
print(sol.maxArea(height))

‎README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ Languages used: Java and Python
9898
- [Permutations II](Medium/Permutations2)
9999
- [Combinations](Medium/Combinations)
100100
- [Longest Palindromic Substring](Medium/LongestPalindromicSubstring)
101+
- [Container With Most Water](Medium/ContainerWithMostWater)
101102

102103
- Hard
103104

@@ -110,6 +111,7 @@ Languages used: Java and Python
110111
- [Escape a Large Maze](Hard/EscapeLargeMaze)
111112
- [Serialize and Deserialize Binary Tree](Hard/SerializeAndDeserializeBinaryTree)
112113
- [Permutation Sequence](Hard/PermutationSequence)
114+
- [Regular Expression Matching](Hard/RegexMatching)
113115

114116
- Others (Non-leetcode)
115117
- [Check Valid Tree Given Edges](Others/CheckValidTreeGivenEdges)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /