Skip to content

Commit 2816562

Browse files
committed
feat: add typescript solution to lc problem: No.2186
No.2186.Minimum Number of Steps to Make Two Strings Anagram II
1 parent 478dc6b commit 2816562

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

solution/2100-2199/2186.Minimum Number of Steps to Make Two Strings Anagram II/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,21 @@
6666
### **TypeScript**
6767

6868
```ts
69+
function minSteps(s: string, t: string): number {
70+
let count1 = new Array(128).fill(0);
71+
let count2 = new Array(128).fill(0);
72+
for (let char of s) {
73+
count1[char.charCodeAt(0)]++;
74+
}
75+
for (let char of t) {
76+
count2[char.charCodeAt(0)]++;
77+
}
78+
let ans = 0;
79+
for (let i = 0; i < 128; i++) {
80+
ans += Math.abs(count1[i] - count2[i]);
81+
}
82+
return ans;
83+
};
6984
```
7085

7186
### **...**

solution/2100-2199/2186.Minimum Number of Steps to Make Two Strings Anagram II/README_EN.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,21 @@ It can be shown that there is no way to make them anagrams of each other with le
5959
### **TypeScript**
6060

6161
```ts
62+
function minSteps(s: string, t: string): number {
63+
let count1 = new Array(128).fill(0);
64+
let count2 = new Array(128).fill(0);
65+
for (let char of s) {
66+
count1[char.charCodeAt(0)]++;
67+
}
68+
for (let char of t) {
69+
count2[char.charCodeAt(0)]++;
70+
}
71+
let ans = 0;
72+
for (let i = 0; i < 128; i++) {
73+
ans += Math.abs(count1[i] - count2[i]);
74+
}
75+
return ans;
76+
};
6277
```
6378

6479
### **...**
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function minSteps(s: string, t: string): number {
2+
let count1 = new Array(128).fill(0);
3+
let count2 = new Array(128).fill(0);
4+
for (let char of s) {
5+
count1[char.charCodeAt(0)]++;
6+
}
7+
for (let char of t) {
8+
count2[char.charCodeAt(0)]++;
9+
}
10+
let ans = 0;
11+
for (let i = 0; i < 128; i++) {
12+
ans += Math.abs(count1[i] - count2[i]);
13+
}
14+
return ans;
15+
};

0 commit comments

Comments
 (0)