We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents d81cdf1 + ae33684 commit 7fc7c8aCopy full SHA for 7fc7c8a
typescript/217-Contains-Duplicate.ts
@@ -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
@@ -0,0 +1,16 @@
+function isAnagram(s: string, t: string): boolean {
+ if (s.length !== t.length) return false;
+ const store = new Array(26).fill(0);
+ for (let i = 0; i < s.length; i++) {
+ store[s.charCodeAt(i) - 'a'.charCodeAt(0)]++;
+ store[t.charCodeAt(i) - 'a'.charCodeAt(0)]--;
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