-
-
Notifications
You must be signed in to change notification settings - Fork 363
[Yiseull] WEEK 03 Solutions #2720
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| class Solution { | ||
| public int hammingWeight(int n) { | ||
| return Integer.bitCount(n); | ||
|
Member
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. 옷, 요런 풀이는 출제 의도와 맞지 않을지도? 면접관이 |
||
| } | ||
| } | ||
|
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. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 두 포인터로 양 끝에서 문자들을 비교하므로 추가 저장소 없이 한 번에 해결한다. 개선 제안: 현재 구현이 적절해 보입니다.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| class Solution { | ||
| public boolean isPalindrome(String s) { | ||
| /** | ||
| 첫 번째 풀이: 시간복잡도 O(n), 공간복잡도 O(n) | ||
| String letters = s.replaceAll("[^a-zA-Z0-9]", "").toLowerCase(); | ||
| String reverse = new StringBuilder(letters).reverse().toString(); | ||
| return letters.equals(reverse); | ||
| */ | ||
|
|
||
| // 두 번째 풀이: 시간복잡도 O(n), 공간복잡도 O(1) | ||
| int left = 0, right = s.length() - 1; | ||
| while (left < right) { | ||
| while (left < right && !Character.isLetterOrDigit(s.charAt(left))) { | ||
| left++; | ||
| } | ||
|
|
||
| while (left < right && !Character.isLetterOrDigit(s.charAt(right))) { | ||
| right--; | ||
| } | ||
|
|
||
| if (Character.toLowerCase(s.charAt(left)) != Character.toLowerCase(s.charAt(right))) { | ||
| return false; | ||
| } | ||
|
|
||
| left++; | ||
| right--; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
| } |
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.
🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 자바 내장 함수로 간단히 비트 수를 셈으로써 상수 시간에 근접한 성능을 낼 수 있다.
개선 제안: 현재 구현이 적절해 보입니다.