Compare commits

...

1 Commits

Author SHA1 Message Date
Lothar Buchholz bbe033c582 optimized array solution 4 years ago

@ -1,20 +1,27 @@
import java.util.*;
import java.io.*;
import java.math.*;
/**
* Template code to help you parse the standard input
* according to the problem statement.
**/
class Solution {
public static void main( String[] args ) {
Scanner in = new Scanner( System.in );
// 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( "value" );
System.out.println( maxProfit );
}
}

Loading…
Cancel
Save