Skip to content

Commit 97d71b9

Browse files
committed
feat: add typescript solution to lc problem: No.2273
No.2273.Find Resultant Array After Removing Anagrams
1 parent aa17c24 commit 97d71b9

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

solution/2200-2299/2273.Find Resultant Array After Removing Anagrams/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,28 @@ class Solution {
9696
### **TypeScript**
9797

9898
```ts
99+
function removeAnagrams(words: string[]): string[] {
100+
const n = words.length;
101+
let ans = [];
102+
ans.push(words[0]);
103+
let pre = countWord(words[0]).join('');
104+
for (let i = 1; i < n; i++) {
105+
let cur = countWord(words[i]).join('');
106+
if (pre !== cur) {
107+
ans.push(words[i]);
108+
pre = cur;
109+
}
110+
}
111+
return ans;
112+
};
99113

114+
function countWord (word: string): number[] {
115+
let count = new Array(128).fill(0);
116+
for (let i = 0; i < word.length; i++) {
117+
count[word.charCodeAt(i)]++;
118+
}
119+
return count;
120+
}
100121
```
101122

102123
### **...**

solution/2200-2299/2273.Find Resultant Array After Removing Anagrams/README_EN.md

+21
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,28 @@ class Solution {
8181
### **TypeScript**
8282

8383
```ts
84+
function removeAnagrams(words: string[]): string[] {
85+
const n = words.length;
86+
let ans = [];
87+
ans.push(words[0]);
88+
let pre = countWord(words[0]).join('');
89+
for (let i = 1; i < n; i++) {
90+
let cur = countWord(words[i]).join('');
91+
if (pre !== cur) {
92+
ans.push(words[i]);
93+
pre = cur;
94+
}
95+
}
96+
return ans;
97+
};
8498

99+
function countWord (word: string): number[] {
100+
let count = new Array(128).fill(0);
101+
for (let i = 0; i < word.length; i++) {
102+
count[word.charCodeAt(i)]++;
103+
}
104+
return count;
105+
}
85106
```
86107

87108
### **...**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function removeAnagrams(words: string[]): string[] {
2+
const n = words.length;
3+
let ans = [];
4+
ans.push(words[0]);
5+
let pre = countWord(words[0]).join('');
6+
for (let i = 1; i < n; i++) {
7+
let cur = countWord(words[i]).join('');
8+
if (pre !== cur) {
9+
ans.push(words[i]);
10+
pre = cur;
11+
}
12+
}
13+
return ans;
14+
};
15+
16+
function countWord (word: string): number[] {
17+
let count = new Array(128).fill(0);
18+
for (let i = 0; i < word.length; i++) {
19+
count[word.charCodeAt(i)]++;
20+
}
21+
return count;
22+
}

0 commit comments

Comments
 (0)