We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 93dca17 commit 5c0fd80Copy full SHA for 5c0fd80
1 file changed
live10/test102/문제2/조진우.js
@@ -0,0 +1,30 @@
1
+const fs = require("fs");
2
+const path = require("path");
3
+
4
+const filePath =
5
+ process.platform === "linux"
6
+ ? "/dev/stdin"
7
+ : path.join(__dirname, "input.txt");
8
9
+const input = fs
10
+ .readFileSync(filePath, "utf8")
11
+ .toString()
12
+ .trim()
13
+ .split("\n")
14
+ .map((line) => line.split(" ").map(Number));
15
16
+function solution(input) {
17
+ const N = input[0];
18
+ const stocks = [...input[1]];
19
+ let max = 0;
20
+ let dp = stocks[0]; // 주식의 최소값을 기억
21
22
+ for (let i = 1; i < N; i++) {
23
+ if (stocks[i] - dp > 0) max = Math.max(max, stocks[i] - dp);
24
+ if (stocks[i] < dp) dp = stocks[i];
25
+ }
26
27
+ return max;
28
+}
29
30
+console.log(solution(input));
0 commit comments