Advertisement
Guest User

Untitled

a guest
Feb 6th, 2022
44
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Solution {
  2.     public int maxProfit(int prices[]) {
  3.         int minprice = Integer.MAX_VALUE;
  4.         int maxprofit = 0;
  5.         for (int i = 0; i < prices.length; i++) {
  6.             if (prices[i] < minprice)
  7.                 minprice = prices[i];
  8.             else if (prices[i] - minprice > maxprofit)
  9.                 maxprofit = prices[i] - minprice;
  10.         }
  11.         return maxprofit;
  12.     }
  13. }
Advertisement
RAW Paste Data Copied
Advertisement