Share simple java solution


  • 0
    R
    public class Solution {
    public int maxProfit(int[] prices) {
        int profit = 0;
        int min = Integer.MAX_VALUE;
        
        for(int i = 0; i < prices.length; i++){
            min = Math.min(min,prices[i]);
            profit = Math.max(profit, prices[i]-min);
        }
        
        return profit;
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.