Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

buy and sell stock

class Solution {
    public int maxProfit(int[] prices) {
        int minimum=Integer.MAX_VALUE;
        int maxprofit=0;
        for(int i=0;i<prices.length;i++){
            if(prices[i]<minimum) minimum=prices[i];
            else if(prices[i]-minimum>maxprofit)    maxprofit=prices[i]-minimum;
        }
        return maxprofit;
        
    }
}
Comment

buy and sell stocks

class Solution:
    def maxProfit(self, prices: List[int]) -> int:
	    if not prices:
		    return 0

	    maxProfit = 0
	    minPurchase = prices[0]
	    for i in range(1, len(prices)):		
		    maxProfit = max(maxProfit, prices[i] - minPurchase)
		    minPurchase = min(minPurchase, prices[i])
	    return maxProfit    
Comment

PREVIOUS NEXT
Code Example
Java :: java unicode characters 
Java :: properties object java 
Java :: my canvas java 
Java :: super 
Java :: |= java operation 
Java :: Java float Keyword 
Java :: kafkalistener annotation pass topic from properties file 
Java :: save file to disk java 
Java :: how does plus works in Java 
Java :: array 2 
Java :: how todo a timeout test java 
Java :: JAVA Declaration Statements 
Java :: repeat a string in java 
Java :: convert kotlin code to java online 
Java :: javax.net.ssl.trustStore trustall 
Java :: add image in loggin view spring boot security 
Java :: java.lang.NullPointerException: Cannot store to double array because is null 
Java :: how to make bidirectional fromated binding 
Java :: add external JARs to java vscode 
Java :: Betrag absolute abs java 
Java :: print method in java 
Java :: programa que convierete un archi de c a java 
Java :: java stack declaration 
Java :: success listener with Glide Android java 
Java :: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type project and qualifiers [@Default] 
Java :: facebook share android Studio 
Java :: java random 8 digit number 
Java :: remove activity from recent list android 
Java :: implement hashmap 
Java :: Java Change values of variables 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =