Best Time to Buy and Sell Stock LeetCode solution in Java

1
class Solution {
2
public int maxProfit(int[] prices) {
3
int lsf = Integer.MAX_VALUE;
4
int op = 0;
5
int pist = 0;
6

7
for (int i = 0; i < prices.length; i++) {
8
if (prices[i] < lsf) {
9
lsf = prices[i];
10
}
11
pist = prices[i] - lsf;
12
if (op < pist) {
13
op = pist;
14
}
15
}
16
return op;
17
}
18
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0