File tree 3 files changed +64
-0
lines changed
solution/2200-2299/2273.Find Resultant Array After Removing Anagrams
3 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -96,7 +96,28 @@ class Solution {
96
96
### ** TypeScript**
97
97
98
98
``` 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
+ };
99
113
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
+ }
100
121
```
101
122
102
123
### ** ...**
Original file line number Diff line number Diff line change @@ -81,7 +81,28 @@ class Solution {
81
81
### ** TypeScript**
82
82
83
83
``` 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
+ };
84
98
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
+ }
85
106
```
86
107
87
108
### ** ...**
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments