forked from code-clash/buy-and-sell-once
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
664 B
Java
28 lines
664 B
Java
import java.util.*;
|
|
|
|
class Solution {
|
|
|
|
public static void main( String[] args ) {
|
|
// read values with in.next...() methods
|
|
var prices = new Scanner( System.in ).tokens()
|
|
.mapToInt( Integer::valueOf )
|
|
.toArray();
|
|
|
|
// code your solution here
|
|
int maxProfit = 0;
|
|
for ( int index = 0; index < prices.length; index++ ) {
|
|
var currentPrice = prices[index];
|
|
|
|
for ( int rem = index + 1; rem < prices.length; rem++ ) {
|
|
var futurePrice = prices[rem];
|
|
var profit = futurePrice - currentPrice;
|
|
maxProfit = Math.max( profit, maxProfit );
|
|
}
|
|
}
|
|
|
|
// Write result with System.out.println()
|
|
System.out.println( maxProfit );
|
|
}
|
|
|
|
}
|