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 aa47fcc commit c86130aCopy full SHA for c86130a
best-time-to-buy-and-sell-stock/wclee2265.cpp
@@ -0,0 +1,15 @@
1
+// https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
2
+
3
+class Solution {
4
+public:
5
+ int maxProfit(vector<int>& prices) {
6
+ int n = prices.size();
7
+ int minimum = prices[0];
8
+ int ans = 0;
9
+ for(int i=1; i<n; i++) {
10
+ ans = max(ans, prices[i] - minimum);
11
+ minimum = min(minimum, prices[i]);
12
+ }
13
+ return ans;
14
15
+};
0 commit comments