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
14 changes: 14 additions & 0 deletions valid-palindrome/jinaSE0.ts

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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Greedy, Hash Map / Hash Set, Two Pointers, Sliding Window, Dynamic Programming, Binary Search, Monotonic Stack, Heap / Priority Queue, DFS, BFS, Backtracking, Divide and Conquer, Union Find, Trie, Bit Manipulation
  • 설명: 주어진 코드는 문자열 전처리 후 뒤집기와 비교하여 회문 여부를 판단합니다. 정확한 패턴으로는 Two Pointers(앞뒤 문자 비교로 회문 판단 가능)나 Sliding Window가 적합하지만 현재 구현은 명시적 반복 비교 대신 문자열 변환으로 해결합니다.

📊 시간/공간 복잡도 분석

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

피드백: 입력 문자열을 한 번 순회하며 정리된 문자열을 만들고, 그 문자열의 대칭 여부를 비교한다. 두 번의 배열 접근이 필요하므로 선형 시간과 선형 추가 공간을 사용한다.

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

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

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.

틀리지 않게 잘 푸신 것 같네요.
추가적인 공간(cleaned, reserved) 없이도 풀이가 가능한 문제니 참고하세요 ~

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function isPalindrome(s: string): boolean {
// 1. 대문자를 모두 소문자로 바꾼다.
const lower = s.toLowerCase()
// 2. 문자와 숫자가 아닌 것은 모두 제거한다.
const cleaned = lower.replace(/[^a-z0-9]/g,"")
// 3. 정리된 문자열 뒤집는다.
const reversed = cleaned.split("").reverse().join("")
// 4. 정리된 문자열과 뒤집은 문자열이 같으면true, 아니면 false
if(cleaned === reversed) {
return true
} else {
return false
}
};
Loading