-
-
Notifications
You must be signed in to change notification settings - Fork 195
[suwi] Week 2 #747
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
Merged
Merged
[suwi] Week 2 #747
Changes from all commits
Commits
Show all changes
4 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,21 @@ | ||
''' | ||
- 달레스터디 풀이 참고함 | ||
풀이 : | ||
n번째 계단을 오르기 위해서는 n-1 또는 n-2에 있다가 올라오는 수 밖에 없으므로 f(n-1) + f(n-2)의 값 | ||
dp 배열로 풀 수도 있지만 두 개의 변수에 업데이트 하는 식으로 풀이 | ||
|
||
TC : | ||
for문으로 인해 O(N) | ||
|
||
SC : | ||
O(1) | ||
''' | ||
|
||
class Solution: | ||
def climbStairs(self, n: int) -> int: | ||
if n < 3 : | ||
return (n) | ||
prv, cur = 1, 2 | ||
for _ in range(3, n + 1) : | ||
prv, cur = cur, prv + cur | ||
return (cur) | ||
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,34 @@ | ||
''' | ||
풀이 : | ||
문자열 s에서 문자가 나올 때마다 딕셔너리에 저장하고 숫자 증가 | ||
문자열 t에서 동일한 문자가 나올 때마다 숫자 감소시키고 0되면 딕셔너리에서 제거 | ||
딕셔너리에 없는 문자가 나오거나 작업이 끝난 후 딕셔너리가 비어있지 않다면 False | ||
|
||
TC : | ||
for문 두번 돌기 때문에 O(N) | ||
|
||
SC : | ||
딕셔너리 할당하는 메모리를 고려하면 O(N) | ||
''' | ||
|
||
class Solution: | ||
def isAnagram(self, s: str, t: str) -> bool: | ||
if len(s) != len(t) : | ||
return (False) | ||
dic = {} | ||
sungjinwi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for char in s : | ||
if char in dic : | ||
dic[char] += 1 | ||
else : | ||
dic[char] = 1 | ||
sungjinwi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for char in t : | ||
if char in dic : | ||
dic[char] -= 1 | ||
if dic[char] == 0 : | ||
dic.pop(char) | ||
else : | ||
return (False) | ||
if dic : | ||
return (False) | ||
else : | ||
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.
Uh oh!
There was an error while loading. Please reload this page.