Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Solution {
- public int maxProfit(int prices[]) {
- int minprice = Integer.MAX_VALUE;
- int maxprofit = 0;
- for (int i = 0; i < prices.length; i++) {
- if (prices[i] < minprice)
- minprice = prices[i];
- else if (prices[i] - minprice > maxprofit)
- maxprofit = prices[i] - minprice;
- }
- return maxprofit;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement