-
-
Notifications
You must be signed in to change notification settings - Fork 245
[hu6r1s] WEEK 03 Solutions #1784
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
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
78f0cd6
feat: Solve valid-palindrome problem
hu6r1s 176ddb4
feat: Solve number-of-1-bits problem
hu6r1s 1ac5131
feat: Solve combination-sum problem
hu6r1s 1c32cb4
feat: Solve maximum-subarray problem
hu6r1s 8cb65c8
feat: Solve decode-ways problem
hu6r1s 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,38 @@ | ||
class Solution: | ||
""" | ||
1. 문자열을 반복문을 돌며 isdigit() or isalpha()이 True라면 string에 붙이기 | ||
반복문이 끝나면 소문자로 모두 변경하고 뒤집은 문자와 같으면 True 반환 | ||
시간 복잡도 (Time Complexity): | ||
- 문자열 순회: O(n) | ||
- 문자열 덧붙이기(string += i): O(n^2) ← 파이썬에서 문자열은 불변이라 매번 새로운 문자열 생성 | ||
- 소문자 변환 및 슬라이싱 비교: 각각 O(n) | ||
최종 시간 복잡도: O(n^2) | ||
|
||
공간 복잡도 (Space Complexity): | ||
- 필터링된 문자열 저장용 string: O(n) | ||
- 역순 문자열 생성: O(n) | ||
최종 공간 복잡도: O(n) | ||
|
||
2. 문자열과 숫자인 것만 뽑아 리스트에 넣기 | ||
시간 복잡도 (Time Complexity): | ||
- 리스트 컴프리헨션: O(n) | ||
- 각 문자에 대해 isalnum() → O(1), lower() → O(1) 이므로 전체 O(n) | ||
- 리스트 슬라이싱 및 비교(string == string[::-1]): O(n) | ||
총 시간 복잡도: O(n) | ||
|
||
공간 복잡도 (Space Complexity): | ||
- 리스트 string에 최대 n개의 문자 저장: O(n) | ||
- 슬라이싱된 string[::-1]도 새로운 리스트를 생성하므로 O(n) | ||
총 공간 복잡도: O(n) | ||
""" | ||
def isPalindrome(self, s: str) -> bool: | ||
# string = "" | ||
|
||
# for i in s: | ||
# if i.isdigit() or i.isalpha(): | ||
# string += i | ||
# string = string.lower() | ||
# return True if string == string[::-1] else False | ||
|
||
string = [i.lower() for i in s if i.isalnum()] | ||
return True if string == string[::-1] else False | ||
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.