File tree Expand file tree Collapse file tree 4 files changed +46
-46
lines changed
solution/3100-3199/3163.String Compression III Expand file tree Collapse file tree 4 files changed +46
-46
lines changed Original file line number Diff line number Diff line change 1- function compressedString ( word ) {
2- let res = '' ;
3-
4- for ( let i = 1 , j = 0 ; i <= word . length ; i ++ ) {
5- if ( word [ i ] !== word [ j ] || i - j === 9 ) {
6- res += i - j + word [ j ] ;
7- j = i ;
8- }
9- }
10-
11- return res ;
12- }
1+ function compressedString ( word ) {
2+ let res = '' ;
3+
4+ for ( let i = 1 , j = 0 ; i <= word . length ; i ++ ) {
5+ if ( word [ i ] !== word [ j ] || i - j === 9 ) {
6+ res += i - j + word [ j ] ;
7+ j = i ;
8+ }
9+ }
10+
11+ return res ;
12+ }
Original file line number Diff line number Diff line change 1- function compressedString ( word : string ) : string {
2- let res = '' ;
3-
4- for ( let i = 1 , j = 0 ; i <= word . length ; i ++ ) {
5- if ( word [ i ] !== word [ j ] || i - j === 9 ) {
6- res += i - j + word [ j ] ;
7- j = i ;
8- }
9- }
10-
11- return res ;
12- }
1+ function compressedString ( word : string ) : string {
2+ let res = '' ;
3+
4+ for ( let i = 1 , j = 0 ; i <= word . length ; i ++ ) {
5+ if ( word [ i ] !== word [ j ] || i - j === 9 ) {
6+ res += i - j + word [ j ] ;
7+ j = i ;
8+ }
9+ }
10+
11+ return res ;
12+ }
Original file line number Diff line number Diff line change 1- function compressedString ( word ) {
2- const regex = / ( .) \1{ 0 , 8 } / g;
3- let m = null ;
4- let res = '' ;
5-
6- while ( ( m = regex . exec ( word ) ) ) {
7- res += m [ 0 ] . length + m [ 1 ] ;
8- }
9-
10- return res ;
11- }
1+ function compressedString ( word ) {
2+ const regex = / ( .) \1{ 0 , 8 } / g;
3+ let m = null ;
4+ let res = '' ;
5+
6+ while ( ( m = regex . exec ( word ) ) ) {
7+ res += m [ 0 ] . length + m [ 1 ] ;
8+ }
9+
10+ return res ;
11+ }
Original file line number Diff line number Diff line change 1- function compressedString ( word : string ) : string {
2- const regex = / ( .) \1{ 0 , 8 } / g;
3- let m : RegExpMatchArray | null = null ;
4- let res = '' ;
5-
6- while ( ( m = regex . exec ( word ) ) ) {
7- res += m [ 0 ] . length + m [ 1 ] ;
8- }
9-
10- return res ;
11- }
1+ function compressedString ( word : string ) : string {
2+ const regex = / ( .) \1{ 0 , 8 } / g;
3+ let m : RegExpMatchArray | null = null ;
4+ let res = '' ;
5+
6+ while ( ( m = regex . exec ( word ) ) ) {
7+ res += m [ 0 ] . length + m [ 1 ] ;
8+ }
9+
10+ return res ;
11+ }
You can’t perform that action at this time.
0 commit comments