File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed
solution/3000-3099/3016.Minimum Number of Pushes to Type Word II Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -189,6 +189,23 @@ function minimumPushes(word: string): number {
189189}
190190```
191191
192+ #### JavaScript
193+
194+ ``` js
195+ function minimumPushes (word ) {
196+ const cnt = Array (26 ).fill (0 );
197+ for (const c of word) {
198+ ++ cnt[c .charCodeAt (0 ) - ' a' .charCodeAt (0 )];
199+ }
200+ cnt .sort ((a , b ) => b - a);
201+ let ans = 0 ;
202+ for (let i = 0 ; i < 26 ; ++ i) {
203+ ans += (((i / 8 ) | 0 ) + 1 ) * cnt[i];
204+ }
205+ return ans;
206+ }
207+ ```
208+
192209<!-- tabs: end -->
193210
194211<!-- solution: end -->
Original file line number Diff line number Diff line change @@ -187,6 +187,23 @@ function minimumPushes(word: string): number {
187187}
188188```
189189
190+ #### JavaScript
191+
192+ ``` js
193+ function minimumPushes (word ) {
194+ const cnt = Array (26 ).fill (0 );
195+ for (const c of word) {
196+ ++ cnt[c .charCodeAt (0 ) - ' a' .charCodeAt (0 )];
197+ }
198+ cnt .sort ((a , b ) => b - a);
199+ let ans = 0 ;
200+ for (let i = 0 ; i < 26 ; ++ i) {
201+ ans += (((i / 8 ) | 0 ) + 1 ) * cnt[i];
202+ }
203+ return ans;
204+ }
205+ ```
206+
190207<!-- tabs: end -->
191208
192209<!-- solution: end -->
Original file line number Diff line number Diff line change 1+ function minimumPushes ( word ) {
2+ const cnt = Array ( 26 ) . fill ( 0 ) ;
3+ for ( const c of word ) {
4+ ++ cnt [ c . charCodeAt ( 0 ) - 'a' . charCodeAt ( 0 ) ] ;
5+ }
6+ cnt . sort ( ( a , b ) => b - a ) ;
7+ let ans = 0 ;
8+ for ( let i = 0 ; i < 26 ; ++ i ) {
9+ ans += ( ( ( i / 8 ) | 0 ) + 1 ) * cnt [ i ] ;
10+ }
11+ return ans ;
12+ }
You can’t perform that action at this time.
0 commit comments