-
-
Notifications
You must be signed in to change notification settings - Fork 340
[hyeri0903] WEEK 06 Solutions #2511
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
Open
hyeri0903
wants to merge
2
commits into
DaleStudy:main
Choose a base branch
from
hyeri0903:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+63
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,26 @@ | ||
| class Solution: | ||
| def lengthOfLIS(self, nums: List[int]) -> int: | ||
| ''' | ||
| 모르겠어서 풀이봤습니다 ㅜㅜ | ||
| 1.problem: 증가하는 가장 긴 subsequence length return (최장 증가 부분 수열) | ||
| 2.조건 | ||
| - nums array 길이 최소 1 , 최대 2500 | ||
| - 원소 값 음수 가능 | ||
| 3.풀이 | ||
| - dp : time complexity O(n^2) | ||
| dp[i] = i번째 원소를 마지막으로하는 LIS | ||
| dp[i] max(dp[i], dp[j]+1) 나 보다 작은 애들 중 가장 긴 LIS + 1 | ||
| ''' | ||
|
|
||
| n = len(nums) | ||
| dp = [1] * (n) | ||
|
|
||
| for i in range(n): | ||
| for j in range(i): | ||
| #앞 숫자 nums[j]가 지금 nums[i]보다 더 작은 경우 dp[i] update | ||
| if nums[j] < nums[i]: | ||
| dp[i] = max(dp[i], dp[j] + 1) | ||
| return max(dp) | ||
|
|
||
|
|
||
|
|
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🏷️ 알고리즘 패턴 분석
|
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,37 @@ | ||
| class Solution: | ||
| def isValid(self, s: str) -> bool: | ||
| ''' | ||
| 문제: string s 에 대해서 valid parentheses 이면 true 아니면 false | ||
| conditions | ||
| - open brackets must be closed by the same type | ||
| - // must be closed in the correct order | ||
| - s 최소 길이 = 1, 최대 10^4 | ||
| solution | ||
| - open brackets -> st array 에 저장, close brackets -> st.pop -> check valid | ||
| - 마지막에 st array length 가 1 이상이면 return False | ||
|
|
||
| - time complexity: O(n) | ||
| - space complexity: O(n) | ||
| ''' | ||
|
|
||
| st = [] | ||
|
|
||
| for i in range(len(s)): | ||
| if s[i] == '(' or s[i] == '{' or s[i] == '[': | ||
| st.append(s[i]) | ||
| else: | ||
| # check if st is empty | ||
| if len(st) <= 0: | ||
| return False | ||
| cur = st.pop() | ||
| if s[i] == ')' and cur != '(': | ||
| return False | ||
| if s[i] == '}' and cur != '{': | ||
| return False | ||
| if s[i] == ']' and cur != '[': | ||
| return False | ||
| if len(st) > 0: | ||
| return False | ||
| return True | ||
|
|
||
|
|
Oops, something went wrong.
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.
🏷️ 알고리즘 패턴 분석