Skip to content

Commit

Permalink
Q121 added.
Browse files Browse the repository at this point in the history
  • Loading branch information
isinsuarici committed Feb 25, 2023
1 parent b176ab2 commit 2e90ac9
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions E_121_BestTimetoBuyandSellStock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution {
public int maxProfit(int[] prices) {
int min=100000;
int max=-1;
int diff=0;
for(int i: prices){
if(i<min){
min=i;
max=-1;
}
else if(max<i){
max=i;
if(max-min>diff){
diff=max-min;
}

}
}
return diff;
}
}

0 comments on commit 2e90ac9

Please sign in to comment.