File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ const input = require ( "fs" )
2+ . readFileSync ( process . platform === "linux" ? "/dev/stdin" : "./input.txt" )
3+ . toString ( )
4+ . trim ( )
5+ . split ( "\n" ) ;
6+
7+ const N = Number ( input [ 0 ] ) ;
8+ const arr = input . map ( Number ) . splice ( 1 ) ;
9+
10+ arr . sort ( ( a , b ) => a - b ) ;
11+
12+ let min = Number . MAX_SAFE_INTEGER ;
13+
14+ for ( let i = 0 ; i < N ; i ++ ) {
15+ const set = new Set ( [ arr [ i ] + 1 , arr [ i ] + 2 , arr [ i ] + 3 , arr [ i ] + 4 ] ) ;
16+ let cnt = 0 ;
17+ for ( let j = 0 ; j < N ; j ++ ) {
18+ if ( set . has ( arr [ j ] ) ) cnt ++ ;
19+ }
20+ min = Math . min ( cnt , min ) ;
21+ }
22+
23+ console . log ( min ) ;
Original file line number Diff line number Diff line change 1+ const input = require ( "fs" )
2+ . readFileSync ( process . platform === "linux" ? "/dev/stdin" : "./input.txt" )
3+ . toString ( )
4+ . trim ( )
5+ . split ( "\n" ) ;
6+
7+ const [ N , M ] = input [ 0 ] . split ( " " ) . map ( Number ) ;
8+ const arr = input [ 1 ] . split ( " " ) . map ( Number ) ;
9+
10+ let cnt = 0 ;
11+
12+ for ( let i = 0 ; i < N ; i ++ ) {
13+ let sum = arr [ i ] ;
14+ let idx = i ;
15+ while ( sum < M && idx < N ) {
16+ idx ++ ;
17+ sum += arr [ idx ] ;
18+ }
19+ if ( sum === M ) cnt ++ ;
20+ }
21+
22+ console . log ( cnt ) ;
Original file line number Diff line number Diff line change 1+ function solution ( numbers ) {
2+ const strNum = numbers . map ( String ) ;
3+ if ( strNum . every ( ( str ) => str === "0" ) ) return "0" ;
4+ strNum . sort ( ( a , b ) => b + a - ( a + b ) ) ;
5+ return strNum . join ( "" ) ;
6+ }
You can’t perform that action at this time.
0 commit comments