We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent abf9a39 commit 91dd214Copy full SHA for 91dd214
best-time-to-buy-and-sell-stock/minji-go.java
@@ -0,0 +1,18 @@
1
+/**
2
+ * <a href="https://leetcode.com/problems/best-time-to-buy-and-sell-stock/">week05-1.best-time-to-buy-and-sell-stock</a>
3
+ * <li>Description: Return the maximum profit you can achieve from this transaction</li>
4
+ * <li>Topics: Array, Dynamic Programming </li>
5
+ * <li>Time Complexity: O(N), Runtime 2ms </li>
6
+ * <li>Space Complexity: O(1), Memory 61.62MB </li>
7
+ */
8
+class Solution {
9
+ public int maxProfit(int[] prices) {
10
+ int min = prices[0];
11
+ int profit = 0;
12
+ for(int i=1; i<prices.length; i++) {
13
+ profit = Math.max(profit, prices[i]-min);
14
+ min = Math.min(min, prices[i]);
15
+ }
16
+ return profit;
17
18
+}
0 commit comments