Skip to content

Commit 53d6dec

Browse files
Create BuySell1Greedy.java
1 parent 9db6629 commit 53d6dec

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class BuySell1Greedy {
2+
public int maxProfit(int[] prices) {
3+
int minValue = Integer.MAX_VALUE;
4+
int maxProfit = Integer.MIN_VALUE;
5+
6+
for(int i = 0; i<prices.length; i++){
7+
minValue = Math.min(prices[i], minValue);
8+
maxProfit = Math.max(maxProfit, prices[i]-minValue);
9+
}
10+
11+
return maxProfit;
12+
}
13+
}

0 commit comments

Comments
 (0)