Skip to content

Commit f620385

Browse files
Add files via upload
1 parent 0caa104 commit f620385

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Besttimetosellandbuy.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class Besttimetosellandbuy {
2+
public static int time(int prices[]){
3+
int buy=Integer.MAX_VALUE;
4+
int sell=0;
5+
for(int i=0;i<prices.length;i++){
6+
buy=Math.min(buy,prices[i]);
7+
sell=Math.max(sell,prices[i]-buy);
8+
}
9+
return sell;
10+
}
11+
public static void main(String[]args){
12+
int prices[]={11,4,7,5,8};
13+
System.out.println(Besttimetosellandbuy.time(prices));
14+
}
15+
}

0 commit comments

Comments
 (0)