-
-
Notifications
You must be signed in to change notification settings - Fork 195
[printjin-gmailcom] Week 06 Solution #1414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+89
−0
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0e87ace
Solve : Valid Parentheses
printjin-gmailcom 57444a4
Merge branch 'DaleStudy:main' into main
printjin-gmailcom f2daef6
Solve : Container With Most Water
printjin-gmailcom 1f36003
Solve : Container With Most Water
printjin-gmailcom 04aab79
Solve : Container With Most Water
printjin-gmailcom 7c69408
Solve : Container With Most Water
printjin-gmailcom 4dc9152
Solve : Design Add And Search Words Data Structure
printjin-gmailcom f6cb1d9
Solve : Longest Increasing Subsequence
printjin-gmailcom 7c7f32d
Solve : Spiral Matrix
printjin-gmailcom 52805fa
Merge branch 'main' of https://github.com/printjin-gmailcom/Dalle_Cod…
printjin-gmailcom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class Solution: | ||
def maxArea(self, height): | ||
left, right = 0, len(height) - 1 | ||
max_area = 0 | ||
while left < right: | ||
h = min(height[left], height[right]) | ||
w = right - left | ||
max_area = max(max_area, h * w) | ||
if height[left] < height[right]: | ||
left += 1 | ||
else: | ||
right -= 1 | ||
return max_area |
33 changes: 33 additions & 0 deletions
33
design-add-and-search-words-data-structure/printjin-gmailcom.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
class TrieNode: | ||
def __init__(self): | ||
self.children = {} | ||
self.is_end = False | ||
|
||
class WordDictionary: | ||
|
||
def __init__(self): | ||
self.root = TrieNode() | ||
|
||
def addWord(self, word): | ||
node = self.root | ||
for ch in word: | ||
if ch not in node.children: | ||
node.children[ch] = TrieNode() | ||
node = node.children[ch] | ||
node.is_end = True | ||
|
||
def search(self, word): | ||
def dfs(index, node): | ||
if index == len(word): | ||
return node.is_end | ||
ch = word[index] | ||
if ch == '.': | ||
for child in node.children.values(): | ||
if dfs(index + 1, child): | ||
return True | ||
return False | ||
if ch in node.children: | ||
return dfs(index + 1, node.children[ch]) | ||
return False | ||
|
||
return dfs(0, self.root) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import bisect | ||
|
||
class Solution: | ||
def lengthOfLIS(self, nums): | ||
subsequence = [] | ||
|
||
for num in nums: | ||
idx = bisect.bisect_left(subsequence, num) | ||
|
||
if idx == len(subsequence): | ||
subsequence.append(num) | ||
else: | ||
subsequence[idx] = num | ||
|
||
return len(subsequence) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class Solution: | ||
def spiralOrder(self, matrix): | ||
result = [] | ||
while matrix: | ||
result += matrix.pop(0) | ||
if matrix and matrix[0]: | ||
for row in matrix: | ||
result.append(row.pop()) | ||
if matrix: | ||
result += matrix.pop()[::-1] | ||
if matrix and matrix[0]: | ||
for row in matrix[::-1]: | ||
result.append(row.pop(0)) | ||
return result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class Solution: | ||
def isValid(self, s): | ||
stack = [] | ||
mapping = {')': '(', '}': '{', ']': '['} | ||
for char in s: | ||
if char in mapping.values(): | ||
stack.append(char) | ||
elif char in mapping: | ||
if not stack or stack[-1] != mapping[char]: | ||
return False | ||
stack.pop() | ||
else: | ||
return False | ||
return not stack |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
list 원소들을 직접 pop하면서 추가해 나가는 과정이 흥미로웠습니다!!