Skip to content

Commit 7fc7c8a

Browse files
Merge pull request neetcode-gh#142 from SandeepGamot/ts-solutions
add: typescript solutions for LC-1,LC-217,LC-242
2 parents d81cdf1 + ae33684 commit 7fc7c8a

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

typescript/217-Contains-Duplicate.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function containsDuplicate(nums: number[]): boolean {
2+
const set = new Set();
3+
4+
for (let i = 0; i < nums.length; i++) {
5+
if (set.has(nums[i])) return true;
6+
else set.add(nums[i]);
7+
}
8+
9+
return false;
10+
}

typescript/242-Valid-Anagrams.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function isAnagram(s: string, t: string): boolean {
2+
if (s.length !== t.length) return false;
3+
4+
const store = new Array(26).fill(0);
5+
6+
for (let i = 0; i < s.length; i++) {
7+
store[s.charCodeAt(i) - 'a'.charCodeAt(0)]++;
8+
store[t.charCodeAt(i) - 'a'.charCodeAt(0)]--;
9+
}
10+
11+
for (let i = 0; i < store.length; i++) {
12+
if (store[i] !== 0) return false;
13+
}
14+
15+
return true;
16+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy