Created
January 2, 2024 18:10
-
-
Save vamsitallapudi/43d7ce3ed6577a887d735ac65c8c5cef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public int maxProfit(int[] prices) { | |
int profit =0; | |
int min = Integer.MAX_VALUE; | |
for(int i = 0; i< prices.length;i++) { | |
if(prices[i] < min) { | |
min = prices[i]; | |
} | |
profit = Math.max(profit, prices[i] - min); | |
} | |
return profit; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment