Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions container-with-most-water/daiyongg-kim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution:
def maxArea(self, height: List[int]) -> int:
left = 0
right = len(height) - 1
max_area = 0
while left < right:
max_area = max(max_area, min(height[left], height[right]) * (right - left))
if height[left] < height[right]:
left += 1
else:
right -= 1
return max_area
42 changes: 42 additions & 0 deletions design-add-and-search-words-data-structure/daiyongg-kim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class TrieNode():
def __init__(self):
self.children = {}
self.word = False

class WordDictionary:

def __init__(self):
self.root = TrieNode()

def addWord(self, word: str) -> None:
curr = self.root
for c in word:
if c not in curr.children:
curr.children[c] = TrieNode()
curr = curr.children[c]
curr.word = True

def search(self, word: str) -> bool:

def dfs(j, root):
curr = root

for i in range(j, len(word)):
c = word[i]

if c == ".":
for child in curr.children.values():
if dfs(i+1, child):
return True
return False
else :
if c not in curr.children:
return False
curr = curr.children[c]
return curr.word
return dfs(0, self.root)

# Your WordDictionary object will be instantiated and called as such:
# obj = WordDictionary()
# obj.addWord(word)
# param_2 = obj.search(word)
14 changes: 14 additions & 0 deletions longest-increasing-subsequence/daiyongg-kim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution:
def lengthOfLIS(self, nums: List[int]) -> int:
if not nums:
return 0

# 모든 위치에서 최소 길이는 1 (자기 자신)
dp = [1] * len(nums)

for i in range(len(nums)):
for j in range(i):
if nums[i] > nums[j]:
dp[i] = max(dp[i], dp[j] + 1)

return max(dp)
27 changes: 27 additions & 0 deletions spiral-matrix/daiyongg-kim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Solution:
def spiralOrder(self, matrix: List[List[int]]) -> List[int]:
res = []
left, right = 0, len(matrix[0])
top, bottom = 0, len(matrix)

while left < right and top < bottom:
for i in range(left, right):
res.append(matrix[top][i])
top += 1

for i in range(top, bottom):
res.append(matrix[i][right - 1])
right -= 1

if not (left < right and top < bottom):
break

for i in range(right -1, left -1, -1):
res.append(matrix[bottom - 1][i])
bottom -= 1

for i in range(bottom - 1, top - 1, -1):
res.append(matrix[i][left])
left += 1

return res
22 changes: 22 additions & 0 deletions valid-parentheses/daiyongg-kim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution:
def isValid(self, s: str) -> bool:
stack = []

for c in s:
if c == '(' or c == '[' or c == '{':
stack.append(c)
else:
if not stack:
return False

cur = stack.pop()
if cur == '(' and c != ')':
return False
if cur == '{' and c != '}':
return False
if cur == '[' and c != ']':
return False
if not stack:
return True
else:
return False