-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
class Solution: | ||
def maxArea(self, height: List[int]) -> int: | ||
right = len(height) - 1 | ||
left = 0 | ||
max_size = 0 | ||
for line in range(len(height)): | ||
if left >= right: | ||
break | ||
cur_size = (right - left) * min(height[left], height[right]) | ||
if height[left] < height[right]: # 왼쪽이 작으면 left 이동 | ||
left += 1 | ||
else: | ||
right -= 1 | ||
max_size = max(max_size, cur_size) | ||
return max_size |
This file contains 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,23 @@ | ||
class Solution: | ||
def lengthOfLIS(self, nums: List[int]) -> int: | ||
dp = [1 for _ in range(len(nums))] | ||
prv = [-1 for _ in range(len(nums))] | ||
for i in range(len(nums)): | ||
for j in range(i + 1, len(nums)): | ||
if nums[i] < nums[j]: | ||
if dp[i] + 1 > dp[j]: | ||
dp[j] = dp[i] + 1 | ||
""" | ||
prv [-1, -1, -1, 2, 2, 3, 5, 5] | ||
dp [ 1, 1, 1, 2, 2, 3, 4, 4] | ||
nums[10, 9, 2, 5, 3, 7, 101, 18] | ||
nums[2] = 2 | ||
nums[4] = 3 | ||
nums[5] = 7 | ||
#dp[j] = max(dp[i] + 1, dp[j]) | ||
# dp[i] + 1 <= dp[j]일 때 dp[j] 갱신X | ||
# LIS길이가 더 적거나 같은 상황. => LIS배열이 업데이트X | ||
""" | ||
return max(dp) | ||
|
This file contains 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,19 @@ | ||
class Solution: | ||
def isValid(self, s: str) -> bool: | ||
# stack 활용, 짝이 맞으면 pop하기 | ||
stack = [] | ||
dic = dict(zip(")}]", "({[")) # close bracket : open bracket 형태로 사전 생성 | ||
for char in s: | ||
if char in "({[": # open bracket인 경우 stack에 추가 | ||
stack.append(char) | ||
elif char in ")}]" : # close bracket이면서 | ||
if not stack or stack.pop() != dic[char]: | ||
return False | ||
|
||
# len()함수 시간복잡도 먹음 O(n) | ||
# => not stack 사용하면 개선됨 | ||
if len(stack) == 0: # stack이 비어있다면 모든 짝이 맞아서 pop되었으므로 true 반환 | ||
return True | ||
else: | ||
return False | ||
|