Skip to content

[Lustellz] WEEK 03 solutions #1807

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

Merged
merged 4 commits into from
Aug 12, 2025
Merged
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
17 changes: 17 additions & 0 deletions valid-palindrome/Lustellz.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function isPalindrome(s: string): boolean {
// https://leetcode.com/problems/valid-palindrome/
// Runtime: 6ms
// Memory: 58.88MB
const convertedString: string = s.replace(/[^a-zA-Z0-9]/g, '').toLowerCase()
let lettersArray: string[]
if(convertedString.length>0){
lettersArray = convertedString.split("")
for(let idx = 0; idx<(lettersArray.length/2); idx++){
if(lettersArray[idx] !== lettersArray[lettersArray.length-idx-1]) return false
Comment on lines +6 to +10
Copy link
Contributor

Choose a reason for hiding this comment

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

잘 되네요

Suggested change
let lettersArray: string[]
if(convertedString.length>0){
lettersArray = convertedString.split("")
for(let idx = 0; idx<(lettersArray.length/2); idx++){
if(lettersArray[idx] !== lettersArray[lettersArray.length-idx-1]) return false
if(convertedString.length>0){
for(let idx = 0; idx<(convertedString.length/2); idx++){
if(convertedString[idx] !== convertedString[convertedString.length-idx-1]) return false

}
}
return true

// what I had done wrong at first: reducing the length of the array
// simple solution: reverse and compare (return convertedString === convertedString.split("").reverse().join(""))
};