20 lines
430 B
Java
20 lines
430 B
Java
|
package com.zerroi.leetcode.Four14;
|
||
|
|
||
|
public class MaxProfit {
|
||
|
public static void main(String[] args) {
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class SolutionSecond {
|
||
|
public int maxProfit(int[] prices) {
|
||
|
int profit = Integer.MIN_VALUE;
|
||
|
int cost = Integer.MAX_VALUE;
|
||
|
for (int price : prices) {
|
||
|
cost = Math.min(cost, price);
|
||
|
profit = Math.max(profit, price - cost);
|
||
|
}
|
||
|
return profit;
|
||
|
}
|
||
|
}
|