File tree Expand file tree Collapse file tree 3 files changed +45
-0
lines changed
solution/2100-2199/2186.Minimum Number of Steps to Make Two Strings Anagram II Expand file tree Collapse file tree 3 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 66
66
### ** TypeScript**
67
67
68
68
``` 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
+ };
69
84
```
70
85
71
86
### ** ...**
Original file line number Diff line number Diff line change @@ -59,6 +59,21 @@ It can be shown that there is no way to make them anagrams of each other with le
59
59
### ** TypeScript**
60
60
61
61
``` 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
+ };
62
77
```
63
78
64
79
### ** ...**
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments