# 122. Best Time to Buy and Sell Stock II

122. Best Time to Buy and Sell Stock II

``````class Solution {
public int maxProfit(int[] prices) {
int profit = 0;
for (int i = 0; i < prices.length-1; i++){
if(prices[i+1] > prices[i]) profit+= (prices[i+1] - prices[i]);
}
return profit;
}
}``````

# 11. Container With Most Water

11. Container With Most Water

``````class Solution {
public int maxArea(int[] height) {
int maxArea =  Integer.MIN_VALUE;
int l = 0;
int r = height.length - 1;
while(l < r){
maxArea = Integer.max(maxArea, Integer.min(height[l],height[r])*(r-l));
if(height[l] < height[r]) l++;
else r--;
}
return maxArea;
}
}``````

# 62. Unique Paths

62. Unique Paths

Dynamic Programming

``````class Solution {
public int uniquePaths(int m, int n) {
if(n ==1 && m ==1) return 1;
int[][] grid = new int[m][n];

for(int i = 1;  i <m; i++){
grid[i][0] = 1;
}

for(int i = 1; i < n; i++){
grid[0][i] = 1;
}
for(int i = 1; i < m; i++){
for(int j = 1; j < n; j++){
grid[i][j] =grid[i-1][j] + grid[i][j-1];
}
}
return grid[m-1][n-1];
}
}``````

# 605. Can Place Flowers

605. Can Place Flowers

```class Solution {
public boolean canPlaceFlowers(int[] flowerbed, int n) {
if(flowerbed.length == 1 && flowerbed[0] == 0) n--;
for(int i = 0; i < flowerbed.length; i++){
if(i ==0 && flowerbed[i] == 0 && i+1 <  flowerbed.length && flowerbed[i+1] == 0){
flowerbed[i] = 1;
n--;
}else if( i == flowerbed.length -1 &&
flowerbed[i] == 0 && i-1 >= 0 &&
flowerbed[i-1] == 0){
flowerbed[i] = 1;
n--;
}
else if(flowerbed[i] == 0  &&
i-1 >= 0 &&
flowerbed[i-1] == 0  &&
i+1 <  flowerbed.length &&
flowerbed[i+1] == 0){
flowerbed[i] = 1;
n--;
}
}
if(n <= 0) return true;
else return false;
}
}```