Skip to content

Instantly share code, notes, and snippets.

@vamsitallapudi
Created January 2, 2024 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vamsitallapudi/43d7ce3ed6577a887d735ac65c8c5cef to your computer and use it in GitHub Desktop.
Save vamsitallapudi/43d7ce3ed6577a887d735ac65c8c5cef to your computer and use it in GitHub Desktop.
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