Skip to content

Commit 61a5099

Browse files
author
Eric
committed
102차 2번 문제풀이
1 parent 5340c75 commit 61a5099

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const input = require('fs')
2+
.readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
3+
.toString()
4+
.trim()
5+
.split('\n')
6+
.map((el) => el.split(' ').map(Number));
7+
8+
function solution(input) {
9+
const N = input[0][0];
10+
const an = input[1];
11+
12+
let current = an[0];
13+
let maxProfit = 0;
14+
15+
for (const a of an) {
16+
maxProfit = Math.max(maxProfit, a - current);
17+
18+
current = Math.min(current, a);
19+
}
20+
21+
return maxProfit;
22+
}
23+
24+
console.log(solution(input));

0 commit comments

Comments
 (0)