diff --git a/Week_04/id_115/leetcode_309_115.java b/Week_04/id_115/leetcode_309_115.java new file mode 100644 index 00000000..cfeacc09 --- /dev/null +++ b/Week_04/id_115/leetcode_309_115.java @@ -0,0 +1,23 @@ +class Solution { + public int maxProfit(int[] prices) { + if (prices.length<2) return 0; + + int buy[]=new int[prices.length]; + int sell[]=new int[prices.length]; + //day0 + buy[0] = -prices[0]; + sell[0]= 0; + + //day1 + buy[1] = Math.max(buy[0],-prices[1]); + sell[1]= Math.max(sell[0],buy[0]+prices[1]); + + for(int i =2;i