From 150518c5172b8f03e115cd207df0446da0e6b638 Mon Sep 17 00:00:00 2001 From: Oudarjya Sen Sarma <36289901+oudarjya718@users.noreply.github.com> Date: Thu, 22 Oct 2020 03:44:48 +0530 Subject: [PATCH 1/4] House Robber House Robber (Maximum amount of money obtained by robbing no two consecutive houses)House Robber (Maximum amount of money obtained by robbing no two consecutive houses) added --- Java/1001.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Java/1001.java diff --git a/Java/1001.java b/Java/1001.java new file mode 100644 index 0000000..3f16f9a --- /dev/null +++ b/Java/1001.java @@ -0,0 +1,19 @@ +class Solution { + public int rob(int[] nums) { + if(nums == null || nums.length == 0){ + return 0; + } + if(nums.length == 2){ + return Math.max(nums[0], nums[1]); + } + + int[] dp = new int[nums.length]; + dp[0] = nums[0]; + dp[1] = Math.max(nums[0], nums[1]); + for(int i = 2; i Date: Thu, 22 Oct 2020 04:03:19 +0530 Subject: [PATCH 2/4] Readme.md updated 1001.java added to readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 46d3d80..4c840ce 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ Or from the Sheet 1 of this [Google Sheet](https://bit.ly/2EUhwnw) | 0983 | [Minimum Cost For Tickets](https://leetcode.com/problems/minimum-cost-for-tickets/) | Here dp(i) is the cost to travel from day days[i] to the end of the plan. if days[j] < days[i] + 1 then j1=j. if days[j] < days[i] + 7 then j=j7. if days[j] < days[i] + 30 then j=j30 . dp(i)=min(dp(j1)+costs[0],dp(j7)+costs[1],dp(j30)+costs[2]) | [Java](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Java/0983.java) | O(n) | O(n) | Medium | Dynamic Programming | [📺](https://www.youtube.com/watch?v=2AnrAlCA578) | | 1347 | [Minimum Number of Steps to Make Two Strings Anagram](https://leetcode.com/problems/minimum-number-of-steps-to-make-two-strings-anagram/) | Add 1 for char in s and remove 1 for char in t | [Java](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Java/1347.java) | O(n+m) | O(1) | Medium | Hash Table Heap | [📺](https://www.youtube.com/watch?v=xXXOpOYWtRE) | | 1352 | [Product of the Last K Numbers](https://leetcode.com/problems/product-of-the-last-k-numbers/) | Add new element to list by multiplying it with previous number and return arr[n-1]/arr[n-k-1] | [Python](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Python/1352.py) | O(1) | O(1) | Medium | Array Design | [📺](https://www.youtube.com/watch?v=8CuVduv0Kyg) | +| 1001 | [House Robber (Maximum amount of money obtained by robbing no two consecutive houses)](hhttps://leetcode.com/problems/house-robber/submissions/) | House Robber (Maximum amount of money obtained by robbing no two consecutive houses) | [Java](https://github.com/oudarjya718/LeetCode-Solutions/blob/master/Java/1001.java) | O(1) | O(1) | Medium | Array Design | [📺](https://www.youtube.com/watch?v=-DTseXJaEXs) | Format From bff55a51bcf2d56e2ab428262557421087787bea Mon Sep 17 00:00:00 2001 From: Oudarjya Sen Sarma <36289901+oudarjya718@users.noreply.github.com> Date: Thu, 22 Oct 2020 15:19:24 +0530 Subject: [PATCH 3/4] Decode Ways Decode Ways (Number of ways to decode a given number in terms of A-Z) Java file added --- Java/1695.java | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Java/1695.java diff --git a/Java/1695.java b/Java/1695.java new file mode 100644 index 0000000..5c97535 --- /dev/null +++ b/Java/1695.java @@ -0,0 +1,27 @@ +class Solution { + public int numDecodings(String s) { + if (s == null || s.charAt(0) == '0') + return 0; + + int n = s.length(); + int[] dp = new int[n+1]; + dp[0] = 1; + dp[1] = 1; + + for(int i = 2; i<=n; i++){ + int first = Integer.parseInt(s.substring(i-1, i)); + int second = Integer.parseInt(s.substring(i-2, i)); + + if(first >= 1 && first <=9){ + dp[i]+=dp[i-1]; + } + if (second >= 10 && second <= 26){ + dp[i] += dp[i-2]; + } + } + return dp[n]; + } +} + + + From f24f1d0aed37684d39eeec0fcc4b3f0bc3d6778a Mon Sep 17 00:00:00 2001 From: Oudarjya Sen Sarma <36289901+oudarjya718@users.noreply.github.com> Date: Thu, 22 Oct 2020 15:50:56 +0530 Subject: [PATCH 4/4] Readme updated Readme updated : Decode ways added. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 4c840ce..c466a09 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,8 @@ Or from the Sheet 1 of this [Google Sheet](https://bit.ly/2EUhwnw) | 1352 | [Product of the Last K Numbers](https://leetcode.com/problems/product-of-the-last-k-numbers/) | Add new element to list by multiplying it with previous number and return arr[n-1]/arr[n-k-1] | [Python](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Python/1352.py) | O(1) | O(1) | Medium | Array Design | [📺](https://www.youtube.com/watch?v=8CuVduv0Kyg) | | 1001 | [House Robber (Maximum amount of money obtained by robbing no two consecutive houses)](hhttps://leetcode.com/problems/house-robber/submissions/) | House Robber (Maximum amount of money obtained by robbing no two consecutive houses) | [Java](https://github.com/oudarjya718/LeetCode-Solutions/blob/master/Java/1001.java) | O(1) | O(1) | Medium | Array Design | [📺](https://www.youtube.com/watch?v=-DTseXJaEXs) | +| 1695 | [Decode Ways (Number of ways to decode a given number in terms of A-Z)](https://leetcode.com/problems/decode-ways/) | Decode Ways (Number of ways to decode a given number in terms of A-Z) | [Java](https://github.com/oudarjya718/LeetCode-Solutions/blob/master/Java/1695.java | O(1) | O(1) | Medium | Array Design | [📺](https://www.youtube.com/watch?v=z4dxKxy8dHk) | + Format | 0000 | [Ques name]() | Algo | [Java]() | O() | O() | Easy | Category | [📺]() |