Answers for "java implementation of stock buy sell problem"

0

java implementation of stock buy sell problem

public int largestProfit(int[] prices) {
    int profit = 0;
    int min = Integer.MAX_VALUE;
    for(int i = 0; i < prices.length; i++) {
        if (prices[i] > min) {
            profit = Math.max(profit, prices[i] - min);
        } else {
            min = prices[i];
        }
    }

    return profit;
}
Posted by: Guest on August-02-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language