File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11const fs = require ( 'fs' ) ;
2- const filePath =
3- process . platform === 'linux' ? '/dev/stdin' : './boj/input.txt' ;
2+ const filePath = process . platform === 'linux' ? '/dev/stdin' : 'input.txt' ;
43let input = fs . readFileSync ( filePath ) . toString ( ) . trim ( ) . split ( '\n' ) ;
54
65let n = Number ( input [ 0 ] . trim ( ) ) ;
@@ -28,4 +27,24 @@ function solution(n, work) {
2827 }
2928 return answer ;
3029}
31- console . log ( solution ( n , work ) ) ; // 4
30+ // console.log(solution(n, work)); // 4
31+
32+ // 2025.04.13
33+ function solution2 ( n , work ) {
34+ const workSorted = work . sort ( ( a , b ) => {
35+ if ( a [ 1 ] === b [ 1 ] ) return a [ 0 ] - b [ 0 ] ;
36+ return a [ 1 ] - b [ 1 ] ;
37+ } ) ;
38+
39+ let cnt = 1 ;
40+ let lastTime = workSorted [ 0 ] [ 1 ] ;
41+ for ( let i = 1 ; i < n ; i += 1 ) {
42+ if ( lastTime <= workSorted [ i ] [ 0 ] ) {
43+ lastTime = workSorted [ i ] [ 1 ] ;
44+ cnt += 1 ;
45+ }
46+ }
47+ return cnt ;
48+ }
49+
50+ console . log ( solution2 ( n , work ) ) ; // 4
You can’t perform that action at this time.
0 commit comments