Skip to content

Commit

Permalink
update 70 java, progress
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed May 20, 2024
1 parent 5553ec7 commit 3b18b46
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 10 deletions.
2 changes: 1 addition & 1 deletion data/progress.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
20240520: 73,200
20240520: 73,200,70
20240519: 207,79,206,213,198
20240518: 212(todo),211,338,208(again)
20240517: 347,253(todo),91(todo),217
Expand Down
18 changes: 9 additions & 9 deletions data/to_review.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
2024-07-14 -> ['73,200']
2024-07-14 -> ['73,200,70']
2024-07-13 -> ['207,79,206,213,198']
2024-07-12 -> ['212(todo),211,338,208(again)']
2024-07-11 -> ['347,253(todo),91(todo),217']
Expand All @@ -9,7 +9,7 @@
2024-07-06 -> ['371']
2024-07-05 -> ['121,252']
2024-07-04 -> ['125']
2024-06-23 -> ['73,200']
2024-06-23 -> ['73,200,70']
2024-06-22 -> ['207,79,206,213,198']
2024-06-21 -> ['212(todo),211,338,208(again)']
2024-06-20 -> ['347,253(todo),91(todo),217']
Expand All @@ -20,27 +20,27 @@
2024-06-15 -> ['371']
2024-06-14 -> ['121,252']
2024-06-13 -> ['125']
2024-06-10 -> ['73,200']
2024-06-10 -> ['73,200,70']
2024-06-09 -> ['207,79,206,213,198']
2024-06-08 -> ['212(todo),211,338,208(again)']
2024-06-07 -> ['347,253(todo),91(todo),217']
2024-06-06 -> ['226,98,253(todo)']
2024-06-05 -> ['104,230,102,100']
2024-06-04 -> ['105,106']
2024-06-03 -> ['242,235']
2024-06-02 -> ['73,200', '371']
2024-06-02 -> ['73,200,70', '371']
2024-06-01 -> ['207,79,206,213,198', '121,252']
2024-05-31 -> ['212(todo),211,338,208(again)', '125']
2024-05-30 -> ['347,253(todo),91(todo),217']
2024-05-29 -> ['226,98,253(todo)']
2024-05-28 -> ['73,200', '104,230,102,100']
2024-05-28 -> ['73,200,70', '104,230,102,100']
2024-05-27 -> ['207,79,206,213,198', '105,106']
2024-05-26 -> ['212(todo),211,338,208(again)', '242,235']
2024-05-25 -> ['73,200', '347,253(todo),91(todo),217', '371']
2024-05-25 -> ['73,200,70', '347,253(todo),91(todo),217', '371']
2024-05-24 -> ['207,79,206,213,198', '226,98,253(todo)', '121,252']
2024-05-23 -> ['73,200', '212(todo),211,338,208(again)', '104,230,102,100', '125']
2024-05-22 -> ['73,200', '207,79,206,213,198', '347,253(todo),91(todo),217', '105,106']
2024-05-21 -> ['73,200', '207,79,206,213,198', '212(todo),211,338,208(again)', '226,98,253(todo)', '242,235']
2024-05-23 -> ['73,200,70', '212(todo),211,338,208(again)', '104,230,102,100', '125']
2024-05-22 -> ['73,200,70', '207,79,206,213,198', '347,253(todo),91(todo),217', '105,106']
2024-05-21 -> ['73,200,70', '207,79,206,213,198', '212(todo),211,338,208(again)', '226,98,253(todo)', '242,235']
2024-05-20 -> ['207,79,206,213,198', '212(todo),211,338,208(again)', '347,253(todo),91(todo),217', '104,230,102,100', '371']
2024-05-19 -> ['212(todo),211,338,208(again)', '347,253(todo),91(todo),217', '226,98,253(todo)', '105,106', '121,252']
2024-05-18 -> ['347,253(todo),91(todo),217', '226,98,253(todo)', '104,230,102,100', '242,235', '125']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,37 @@ public class ClimbingStairs {
// IDEA : DP
public int climbStairs(int n) {

if (n <= 2){
if (n == 1){
return 1;
}
return 2;
}

/**
*
* 0, 1, 2, 3..... k-2, k-1, k
* dp[k] = dp[k-2] + dp[k-1]
*
*/

// init dp
int[] dp = new int[n+1];
dp[0] = 1;
dp[1] = 2;

for (int i = 2; i < n; i++){
dp[i] = dp[i-2] + dp[i-1];
//System.out.println("dp[i] = " + dp[i]);
}

return dp[n-1];
}

// V0
// IDEA : DP
public int climbStairs_0(int n) {

// null check
if (n <= 0){
return 0;
Expand Down
31 changes: 31 additions & 0 deletions leetcode_java/src/main/java/dev/workspace3.java
Original file line number Diff line number Diff line change
Expand Up @@ -1187,4 +1187,35 @@ public boolean dfs_help(char[][] grid, int x, int y){
return true;
}

// LC 70
public int climbStairs(int n) {

if (n <= 2){
if (n == 1){
return 1;
}
return 2;
}

/**
*
* 0, 1, 2, 3..... k-2, k-1, k
* dp[k] = dp[k-2] + dp[k-1]
*
*/

int[] dp = new int[n+1];
dp[0] = 1;
dp[1] = 2;

for (int i = 2; i < n; i++){
//dp[i] = Math.max(dp[i-2]+1, dp[i-1]);
dp[i] = dp[i-2] + dp[i-1];
//System.out.println("dp[i] = " + dp[i]);
}

return dp[n-1];
}


}

0 comments on commit 3b18b46

Please sign in to comment.