Skip to content
13 changes: 13 additions & 0 deletions container-with-most-water/printjin-gmailcom.py
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 design-add-and-search-words-data-structure/printjin-gmailcom.py
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)
15 changes: 15 additions & 0 deletions longest-increasing-subsequence/printjin-gmailcom.py
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)
14 changes: 14 additions & 0 deletions spiral-matrix/printjin-gmailcom.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list 원소들을 직접 pop하면서 추가해 나가는 과정이 흥미로웠습니다!!

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
14 changes: 14 additions & 0 deletions valid-parentheses/printjin-gmailcom.py
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