My simple Java DP


  • 0
    S

    public class Solution {
    public int maxProfit(int[] prices) {
    int min,profile=0;
    if(prices.length==0)
    return 0;
    min=prices[0];
    for(int i=1; i<prices.length; i++)
    {
    min=Math.min(prices[i], min);
    profile=Math.max(prices[i]-min, profile);
    }
    return profile;
    }
    }


Log in to reply
 

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