File tree Expand file tree Collapse file tree 5 files changed +77
-0
lines changed
Expand file tree Collapse file tree 5 files changed +77
-0
lines changed Original file line number Diff line number Diff line change 1+ function solution ( board , moves ) {
2+ let N = board . length ;
3+ let stack = [ ] ;
4+ let count = 0 ;
5+ for ( let i = 0 ; i < moves . length ; i ++ ) {
6+ for ( let j = 0 ; j < N ; j ++ ) {
7+ if ( board [ j ] [ moves [ i ] - 1 ] !== 0 ) {
8+ stack . push ( board [ j ] [ moves [ i ] - 1 ] ) ;
9+ if ( stack [ stack . length - 1 ] == stack [ stack . length - 2 ] ) {
10+ count ++ ;
11+ count ++ ;
12+ stack . pop ( ) ;
13+ stack . pop ( ) ;
14+ }
15+ board [ j ] [ moves [ i ] - 1 ] = 0 ;
16+ break ;
17+ }
18+ }
19+ }
20+ return count ;
21+ }
Original file line number Diff line number Diff line change 1+ function solution ( numbers ) {
2+ const strN = [
3+ "zero" ,
4+ "one" ,
5+ "two" ,
6+ "three" ,
7+ "four" ,
8+ "five" ,
9+ "six" ,
10+ "seven" ,
11+ "eight" ,
12+ "nine" ,
13+ ] ;
14+
15+ strN . forEach ( ( nums , index ) => {
16+ numbers = numbers . split ( nums ) . join ( index ) ;
17+ } ) ;
18+
19+ return Number ( numbers ) ;
20+ }
Original file line number Diff line number Diff line change 1+ function solution ( my_string ) {
2+ const splited = my_string . split ( " " ) ;
3+
4+ let ans = Number ( splited [ 0 ] ) ;
5+
6+ splited . forEach ( ( item , index ) => {
7+ if ( item === "+" ) {
8+ ans += Number ( splited [ index + 1 ] ) ;
9+ }
10+
11+ if ( item === "-" ) {
12+ ans -= Number ( splited [ index + 1 ] ) ;
13+ }
14+ } ) ;
15+
16+ return ans ;
17+ }
Original file line number Diff line number Diff line change 1+ function solution ( my_string ) {
2+ let arr = [ ] ;
3+ for ( let i = 0 ; i < my_string . length ; i ++ ) {
4+ arr . push ( my_string [ i ] ) ;
5+ }
6+ let newarr = arr . sort ( function ( a , b ) {
7+ return a - b ;
8+ } ) ;
9+ let answer = newarr . toString ( ) ;
10+ return answer ;
11+ }
Original file line number Diff line number Diff line change 1+ function solution ( s ) {
2+ const stack = [ ] ;
3+ s . split ( " " ) . forEach ( ( target ) => {
4+ if ( target === "Z" ) stack . pop ( ) ;
5+ else stack . push ( + target ) ;
6+ } ) ;
7+ return stack . length ? stack . reduce ( ( pre , cur ) => pre + cur ) : 0 ;
8+ }
You can’t perform that action at this time.
0 commit comments