From 67f91018951f4818330cb43788e306a20cfe1c60 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 26 Jul 2025 23:44:41 +0900 Subject: [PATCH 1/2] two-sum & contains-duplicate solutions --- contains-duplicate/Lustellz.ts | 7 +++++++ two-sum/Lustellz.ts | 6 ++++++ 2 files changed, 13 insertions(+) create mode 100644 contains-duplicate/Lustellz.ts create mode 100644 two-sum/Lustellz.ts diff --git a/contains-duplicate/Lustellz.ts b/contains-duplicate/Lustellz.ts new file mode 100644 index 000000000..c3250a573 --- /dev/null +++ b/contains-duplicate/Lustellz.ts @@ -0,0 +1,7 @@ +function containsDuplicate(nums: number[]): boolean { + let tmp: number[] = nums.toSorted() + for(let i = 0 ; i < nums.length - 1 ; i++){ + if(tmp[i]===tmp[i+1]) return true + } + return false +}; diff --git a/two-sum/Lustellz.ts b/two-sum/Lustellz.ts new file mode 100644 index 000000000..6a8758c3c --- /dev/null +++ b/two-sum/Lustellz.ts @@ -0,0 +1,6 @@ +function twoSum(nums: number[], target: number){ + for(let i = 0; i < nums.length; i++){ + for(let j = i+1; nums.length-j;j++) + if(nums[j] === target - nums[i]) return [i, j] + } +}; From 1671464ddf60a2d37834f11882aae7d61a127a05 Mon Sep 17 00:00:00 2001 From: Tasha <45252527+Lustellz@users.noreply.github.com> Date: Sat, 9 Aug 2025 23:15:25 +0900 Subject: [PATCH 2/2] solution on valid-palindrome --- valid-palindrome/Lustellz.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 valid-palindrome/Lustellz.ts diff --git a/valid-palindrome/Lustellz.ts b/valid-palindrome/Lustellz.ts new file mode 100644 index 000000000..83a38e172 --- /dev/null +++ b/valid-palindrome/Lustellz.ts @@ -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 + } + } + 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("")) +};