-
-
Notifications
You must be signed in to change notification settings - Fork 363
[dahyeong-yun] WEEK 03 Solutions #2724
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
dahyeong-yun
wants to merge
2
commits into
DaleStudy:main
Choose a base branch
from
dahyeong-yun: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.
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,43 @@ | ||
| /** | ||
| * [풀이 개요] | ||
| * - 시간복잡도 : O(n) | ||
| * - 공간복잡도 : O(1) | ||
| */ | ||
| class Solution { | ||
| /** | ||
| * [문제 풀이 아이디어] | ||
| * - 주어진 문자열의 길이가 최대 10^5 이므로 10^8 까지 통과할 수 있다고 가정할 때, 시간복잡도는 O (n log n)까지 가능해 보임 | ||
| * - 문자열 s의 시작과 끝 인덱스가 각각 x, y 라고 할 때 s[x] == s[y], s[x+1] == s[y-1], s[x+2] == s[y-2], s[x+n] == s[y-n] (n은 문자열 중간 인덱스 까지) 와 같이 검증할 수 있음. | ||
| * - 즉 투포인터 형태가 될 수 있어 보임. | ||
| * - 다만 알파벳이 아닌 문자는 제외하고 판단해야 하므로 포인터가 정확히 같은 값을 x, y에서 빼는 형태가 될 수는 없고, 비교 대상이 아닌 인덱스를 넘어가서 다음에 판단해야 함. | ||
| * - 이렇게 순회할 경우 문자열 길이 n의 1/2 를 순회하므로 시간복잡도는 O(n) 이 됨. | ||
| * - 매 char 변수 이외에 추가 공간이 필요치 않으므로 공간복잡도는 O(1) 이 됨. | ||
| */ | ||
| public boolean isPalindrome(String s) { | ||
| int len = s.length(); | ||
| if(len == 1) return true; | ||
|
|
||
| int left = 0; | ||
| int right = len - 1; | ||
|
|
||
| while(left < right) { | ||
| char leftChar = Character.toLowerCase(s.charAt(left)); | ||
| char rightChar = Character.toLowerCase(s.charAt(right)); | ||
|
|
||
| // 문자가 아닌 경우 다음 인덱스 확인 | ||
| if(!Character.isLetterOrDigit(leftChar)) { | ||
| left++; | ||
| } else if(!Character.isLetterOrDigit(rightChar)) { | ||
| right--; | ||
|
|
||
| // 동일한 경우 다음 인덱스 확인 | ||
| } else if(leftChar == rightChar) { | ||
| left++; | ||
| right--; | ||
| } else { | ||
| 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.
🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 왼쪽과 오른쪽 포인터를 이용해 한 번에 중심으로 진행하며, 알파벳과 숫자 여부를 판별하고 필요 시 건너뛰는 방식으로 시간 복잡도를 필요 최소로 유지한다.
개선 제안: 현재 구현이 적절해 보입니다.