Skip to content

Commit fdbc181

Browse files
author
jinbeom
committed
Fix
1 parent e23a34e commit fdbc181

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

3sum/kayden.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ def threeSum2(self, nums: List[int]) -> List[List[int]]:
5050
while nums[l] == nums[l - 1] and l < r:
5151
l += 1
5252

53+
while nums[r] == nums[r + 1] and l < r:
54+
r -= 1
55+
5356
if nums[l] + nums[r] < -nums[i]:
5457
l += 1
5558

word-break/kayden.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
# 시간복잡도: ?
1+
# 시간복잡도: O(S*W)
2+
# S: s의 길이 300 W: worDict 각 단어의 총 길이 20*1000
3+
# 300 * 20*1000 = 6*1e6 (600만)
24
# 공간복잡도: O(S)
35
class Solution:
46
def wordBreak(self, s: str, wordDict: List[str]) -> bool:
57
memo = {}
6-
wordSet = set(wordDict)
7-
88
def dfs(idx):
99
if idx in memo:
1010
return memo[idx]
1111

1212
if idx == len(s):
1313
return True
1414

15-
for word in wordSet:
15+
for word in wordDict:
1616
l = len(word)
1717
if s[idx:idx + l] == word:
1818
if dfs(idx + l):

0 commit comments

Comments
 (0)