File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ package Grind169 .Arrays ;
2+
3+ public class BestTimeToBuySellStock_121 {
4+ public static void main (String [] args ) {
5+
6+ }
7+
8+ public static int maxProfit (int [] prices ){
9+ int minPrice =Integer .MAX_VALUE ;
10+ int profit =0 ;
11+ int pist =0 ;
12+
13+ for (int i =0 ; i < prices .length ; i ++){
14+ if (prices [i ] < minPrice ){
15+ minPrice = prices [i ];
16+ }
17+
18+ pist = minPrice - prices [i ];
19+
20+ if (profit < pist ){
21+ profit = pist ;
22+ }
23+
24+ }
25+
26+ return profit ;
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ package Grind169 .Arrays ;
2+
3+ public class ProductArrExceptSelf_238 {
4+ public static void main (String [] args ) {
5+
6+ }
7+
8+ public static int [] productExceptSelf (int [] nums ) {
9+ int [] result =new int [nums .length ];
10+
11+ for (int i =0 , j =1 ; i <nums .length ; i ++){
12+ result [i ]=j ;
13+ j *=nums [i ];
14+ }
15+
16+ for (int i = nums .length - 1 , j = 1 ; i >= 0 ; i --) {
17+ result [i ] *= j ;
18+ j *= nums [i ];
19+ }
20+ return result ;
21+ }
22+ }
You can’t perform that action at this time.
0 commit comments