Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e1bca48

Browse files
committed
update on leetcode problems
1 parent 1dbcf98 commit e1bca48

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
}

0 commit comments

Comments
 (0)