We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5340c75 commit 61a5099Copy full SHA for 61a5099
1 file changed
live10/test102/문제2/황장현.js
@@ -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