Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions number-of-1-bits/Yiseull.java

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Bit Manipulation
  • 설명: 주어진 코드는 정수의 1비트 개수를 세기 위해 비트 연산을 사용합니다. 내부적으로 비트카운트 함수를 호출해 비트 조작 기법을 이용한 문제 풀이에 해당합니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(1)
Space O(1)

피드백: 자바 내장 함수로 간단히 비트 수를 셈으로써 상수 시간에 근접한 성능을 낼 수 있다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

옷, 요런 풀이는 출제 의도와 맞지 않을지도? 면접관이 Integer.bitCount이 어떻게 동작하는 깊고 파고 들면 인터뷰가 말릴 수도 있고요. 코딩 테스트에서 표준 라이브러리를 사용하는 것은 양날의 검이 될 수 있으니 참고 바랍니다.

}
}
31 changes: 31 additions & 0 deletions valid-palindrome/Yiseull.java

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers, Sliding Window, Hash Map / Hash Set
  • 설명: 문자열의 양 끝에서 문자 여부를 확인하며 비교하는 구조로, 좌우 포인터를 이동시키는 Two Pointers 패턴이 핵심이다. 필요 시 비문자도 건너뛰는 로직은 창 길이 조정 없이 양쪽 포인터를 직접 움직이는 방식으로 구성된다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n)
Space O(1)

피드백: 두 포인터로 양 끝에서 문자들을 비교하므로 추가 저장소 없이 한 번에 해결한다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

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;
}
}
Loading