From 75725e32001ee2de02474838d14d7e09b7dbb042 Mon Sep 17 00:00:00 2001 From: Oudarjya Sen Sarma <36289901+oudarjya718@users.noreply.github.com> Date: Thu, 22 Oct 2020 20:07:22 +0530 Subject: [PATCH 1/3] 0070 | Easy 0070 | Easy | Climbing Stairs (Number of ways to reach top of steps by taking 1 or 2 steps) added --- Java/0070.java | 91 +++++++------------------------------------------- 1 file changed, 12 insertions(+), 79 deletions(-) diff --git a/Java/0070.java b/Java/0070.java index dd0c7ec..e3ac7cd 100644 --- a/Java/0070.java +++ b/Java/0070.java @@ -1,79 +1,12 @@ -class Solution { - public int climbStairs(int n) { - if (n==1) return 1; - - int first = 1; - int second = 2; - - for (int i=3; i<=n; i++){ - int third = first + second; - first = second; - second = third; - } - - return second; - } -} - - -/* - -Time - O(n) -Space - O(1) - - -[_, _, _, _, _, _] - - n = 6 - - n != 1, continue next lines - - dp[] - size 6 - dp = [0, 0, 0, 0, 0, 0] - dp = [1, 0, 0, 0, 0, 0] - dp = [1, 2, 0, 0, 0, 0] - - i = 2 to 5 (n-1) - - i=2 - dp[2] = dp[1] + dp[0] = 2 + 1 = 3 - dp = [1, 2, 3, 0, 0, 0] - - i=3 - dp[3] = dp[2] + dp[1] = 3 + 2 = 5 - dp = [1, 2, 3, 5, 0, 0] - - i=4 - dp[4] = dp[3] + dp[2] = 5 + 3 = 8 - dp = [1, 2, 3, 5, 8, 0] - - i=5 - dp[5] = dp[4] + dp[3] = 8 + 5 = 13 - dp = [1, 2, 3, 5, 8, 13] - - return dp[n-1] - // return dp[5] - // return 13 - - - // Dynamic Programming Solution - - class Solution { - public int climbStairs(int n) { - if (n==1) return 1; - - int[] dp = new int[n]; - dp[0] = 1; - dp[1] = 2; - - for (int i=2;i Date: Thu, 22 Oct 2020 20:30:14 +0530 Subject: [PATCH 2/3] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 46d3d80..4ee83c5 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,8 @@ Or from the Sheet 1 of this [Google Sheet](https://bit.ly/2EUhwnw) | 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) | +| 0070 | [Climbing Stairs (Number of ways to reach top of steps by taking 1 or 2 steps) ](https://leetcode.com/problems/climbing-stairs/) | Number of ways to reach top of steps by taking 1 or 2 steps | [Python](https://github.com/oudarjya718/LeetCode-Solutions/blob/master/Java/0070.java) | O(1) | O(1) | Medium | Array Design | [📺](https://www.youtube.com/watch?v=QiD2Hbwx2z0) | + Format | 0000 | [Ques name]() | Algo | [Java]() | O() | O() | Easy | Category | [📺]() | From b74a1f9208f36e44e19fddd69d1904dfcde7e3c1 Mon Sep 17 00:00:00 2001 From: Oudarjya Sen Sarma <36289901+oudarjya718@users.noreply.github.com> Date: Fri, 23 Oct 2020 16:03:48 +0530 Subject: [PATCH 3/3] readme updated in correct order 0070 solution added in python --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4ee83c5..729890b 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ Or from the Sheet 1 of this [Google Sheet](https://bit.ly/2EUhwnw) | 0055 | [Jump Game](https://leetcode.com/problems/jump-game/) | Iterate from last index and check if we can reach there from current index or not | [Python](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Python/0055.py) | O(n) | O(1) | Medium | Array Greedy | [📺](https://www.youtube.com/watch?v=ymET7SJsDQc) | | 0062| [Unique Paths (Total no of unique paths in m x n matrix)](https://leetcode.com/problems/unique-paths/) | As the first element in each row will always be 1, so maintaining one row is enough to reach bottom-right corner of the grid | [Java]() | O(n) | O(1) | Medium |Array Dynamic Programming | | | 0070 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs/) | steps[n]=steps[n-1]+steps[n-2]. | [C++](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/C++/0070.cpp) [Python](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Python/0070.py) | O(n) | O(1) | Easy | Dynamic Programming | [📺](https://www.youtube.com/watch?v=QiD2Hbwx2z0) | +| 0070 | [Climbing Stairs (Number of ways to reach top of steps by taking 1 or 2 steps) ](https://leetcode.com/problems/climbing-stairs/) | Number of ways to reach top of steps by taking 1 or 2 steps | [Python](https://github.com/oudarjya718/LeetCode-Solutions/blob/master/Java/0070.java) | O(1) | O(1) | Medium | Array Design | [📺](https://www.youtube.com/watch?v=QiD2Hbwx2z0) | + | 0072 | [Edit Distance](https://leetcode.com/problems/edit-distance/) | minDis(i,j)=min(minDis(i-1,j),minDis(i,j-1),minDis(i-1,j-1))+1; | [Java](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Java/0072.py) | O(m*n) | O(m*n) | Hard | String Dynamic programming | | 0073 | [Set Matrix Zeroes](https://leetcode.com/problems/set-matrix-zeroes/) | Use the first cell of every row and column as a flag. This flag would determine whether a row or column has been set to zero. | [C++](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/C++/0073.cpp) [Python](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Python/0073.py) | O(m*n) | O(1) | Medium | Array | [📺](https://www.youtube.com/watch?v=W1I7slnETp4) | | 0075 | [Sort an array of 0’s 1’s 2’s without using extra space or sorting algo](https://leetcode.com/problems/sort-colors/) | the logic is to count total number of 0's, 1's and 2's int the list and starting from beginning first append total 0's then total 1's and then 2's| [Python](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Python/0075.py) | O(n) | O(1) | Medium | Array | [📺](https://www.youtube.com/watch?v=BL9H4zIFHHw&list=PLsowTcGqVtPgo0VSIUIbcOgNQJzblGnst&index=11) | @@ -41,7 +43,6 @@ Or from the Sheet 1 of this [Google Sheet](https://bit.ly/2EUhwnw) | 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) | -| 0070 | [Climbing Stairs (Number of ways to reach top of steps by taking 1 or 2 steps) ](https://leetcode.com/problems/climbing-stairs/) | Number of ways to reach top of steps by taking 1 or 2 steps | [Python](https://github.com/oudarjya718/LeetCode-Solutions/blob/master/Java/0070.java) | O(1) | O(1) | Medium | Array Design | [📺](https://www.youtube.com/watch?v=QiD2Hbwx2z0) | Format