We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 564c3e7 commit 91eb360Copy full SHA for 91eb360
2 files changed
허현빈/6주차/260205-1.js
@@ -0,0 +1,9 @@
1
+var maxProfit = function(prices) {
2
+ let totalProfit = 0;
3
+ for (let i = 0; i < prices.length - 1; i++) {
4
+ if (prices[i] < prices[i+1]) {
5
+ totalProfit += prices[i+1] - prices[i];
6
+ }
7
8
+ return totalProfit;
9
+};
허현빈/6주차/260205-2.js
@@ -0,0 +1,18 @@
+/**
+ * @param {number[]} prices
+ * @return {number}
+ */
+ if (prices.length === 0) return 0;
+
+ let n = prices.length;
+ let dp = new Array(n).fill(0);
10
11
+ for (let i = 1; i < n; i++) {
12
+ let currentChange = prices[i] - prices[i-1];
13
+ dp[i] = Math.max(0, dp[i-1] + currentChange);
14
+ ;
15
16
17
+ return Math.max(...dp);
18
0 commit comments