Skip to content

Latest commit

 

History

History
21 lines (17 loc) · 466 Bytes

leetcode-121.md

File metadata and controls

21 lines (17 loc) · 466 Bytes

Question

Link

Solution

class Solution {
    public int maxProfit(int[] prices) {
        
        int minPrice = 10000;
        int n = prices.length;
        int maxPrice=0;
        
        for(int i =0; i<n;i++){
            minPrice = Math.min(minPrice, prices[i]);
            maxPrice = Math.max(maxPrice, prices[i] - minPrice);
        }
        return maxPrice;
    }
}