Skip to content
Open
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
23 changes: 23 additions & 0 deletions valid-palindrome/hoonjichoi1.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, Greedy
  • 설명: 문자열을 앞뒤에서 동시에 비교하는 방식으로 대칭 여부를 확인하므로 Two Pointers 패턴에 속하며, 최적화 없이 좌우 포인터로 비교하는 간단한 탐색으로 구현됩니다. 이 풀이는 특정한 최적화 기법이나 다른 패턴은 사용하지 않습니다.

📊 시간/공간 복잡도 분석

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

피드백: 입력 문자열을 한 번 거쳐 정규화하고, 정규화된 문자열의 양 끝에서 한 바퀴씩 비교한다. 추가적인 자료구조 없이 문자열 길이에 비례하는 공간을 사용한다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Solution {
public boolean isPalindrome(String s) {

// removing all non-alphanumeric characters and convert them to lower case
String conveted = s.replaceAll("[^a-zA-Z0-9]", "").toLowerCase();

// early return of the empty string case
if (conveted.length() == 0) {
return true;
}

// check the symmetry
int left = 0, right = conveted.length() - 1;
while (left <= right) {
if (conveted.charAt(left) != conveted.charAt(right)) {
return false;
}
left++;
right--;
}
return true;
}
}
Loading