Skip to content

Commit

Permalink
add 91 java, update progress
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Mar 4, 2024
1 parent dbfb13b commit 2a7f3c4
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@
064| [Minimum Path Sum](https://leetcode.com/problems/minimum-path-sum/)| [Python](./leetcode_python/Dynamic_Programming/minimum-path-sum.py) | _O(m * n)_ | _O(m + n)_ | Medium |`DP`, `amazon`| AGAIN*
070| [Climbing Stairs](https://leetcode.com/problems/climbing-stairs/)| [Python](./leetcode_python/Dynamic_Programming/climbing-stairs.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/DynamicProgramming/ClimbingStairs.java)| _O(logn)_ | _O(1)_| Easy| Curated Top 75, Matrix Exponentiation, `DP`, `recursion`, `apple`| OK* (2)
072| [Edit Distance](https://leetcode.com/problems/edit-distance/)| [Python](./leetcode_python/Dynamic_Programming/edit-distance.py) | _O(logn)_ | _O(1)_| Hard| top 100 like, `DP`, `recursion`, `apple`, google, amazon| again (not start)
091| [Decode Ways](https://leetcode.com/problems/decode-ways/) | [Python](./leetcode_python/Dynamic_Programming/decode-ways.py) | _O(n)_ | _O(1)_ | Medium |Curated Top 75, `good basic`,`dp`, `M$`, `UBER`, `amazon`,`fb`| AGAIN************ (4)
091| [Decode Ways](https://leetcode.com/problems/decode-ways/) | [Python](./leetcode_python/Dynamic_Programming/decode-ways.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/DynamicProgramming/DecodeWays.java) | _O(n)_ | _O(1)_ | Medium |Curated Top 75, `good basic`,`dp`, `M$`, `UBER`, `amazon`,`fb`| AGAIN************ (4)
096| [Unique Binary Search Trees](https://leetcode.com/problems/unique-binary-search-trees/) | [Python](./leetcode_python/Dynamic_Programming/unique-binary-search-trees.py) | _O(n)_| _O(1)_| Medium| dp, Math, fb, amazon| AGAIN* (2) (not start)
120| [Triangle](https://leetcode.com/problems/triangle/) | [Python](./leetcode_python/Dynamic_Programming/triangle.py) | _O(m * n)_ | _O(n)_ | Medium |`amazon`| AGAIN* (not start) (2)
123| [Best Time to Buy and Sell Stock III](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/)| [Python](./leetcode_python/Dynamic_Programming/best-time-to-buy-and-sell-stock-iii.py) | _O(m * n)_ | _O(n)_ | Hard |`amazon`, uber, apple| AGAIN* (not start) (1)
Expand Down
2 changes: 1 addition & 1 deletion data/progress.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
20240304: 73,76,79(again)
20240304: 73,76,79(again),91
20240303: 55(again),56,62,70
20240229: 39,48(again),49,53,54
20240228: 20,21,23,33(again)
Expand Down
18 changes: 9 additions & 9 deletions data/to_review.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
2024-04-28 -> ['73,76,79(again)']
2024-04-28 -> ['73,76,79(again),91']
2024-04-27 -> ['55(again),56,62,70']
2024-04-24 -> ['39,48(again),49,53,54']
2024-04-23 -> ['20,21,23,33(again)']
2024-04-22 -> ['1,3,5,4,19']
2024-04-07 -> ['73,76,79(again)']
2024-04-07 -> ['73,76,79(again),91']
2024-04-06 -> ['55(again),56,62,70']
2024-04-03 -> ['39,48(again),49,53,54']
2024-04-02 -> ['20,21,23,33(again)']
2024-04-01 -> ['1,3,5,4,19']
2024-03-25 -> ['73,76,79(again)']
2024-03-25 -> ['73,76,79(again),91']
2024-03-24 -> ['55(again),56,62,70']
2024-03-21 -> ['39,48(again),49,53,54']
2024-03-20 -> ['20,21,23,33(again)']
2024-03-19 -> ['1,3,5,4,19']
2024-03-17 -> ['73,76,79(again)']
2024-03-17 -> ['73,76,79(again),91']
2024-03-16 -> ['55(again),56,62,70']
2024-03-13 -> ['39,48(again),49,53,54']
2024-03-12 -> ['73,76,79(again)', '20,21,23,33(again)']
2024-03-12 -> ['73,76,79(again),91', '20,21,23,33(again)']
2024-03-11 -> ['55(again),56,62,70', '1,3,5,4,19']
2024-03-09 -> ['73,76,79(again)']
2024-03-09 -> ['73,76,79(again),91']
2024-03-08 -> ['55(again),56,62,70', '39,48(again),49,53,54']
2024-03-07 -> ['73,76,79(again)', '20,21,23,33(again)']
2024-03-06 -> ['73,76,79(again)', '55(again),56,62,70', '1,3,5,4,19']
2024-03-05 -> ['73,76,79(again)', '55(again),56,62,70', '39,48(again),49,53,54']
2024-03-07 -> ['73,76,79(again),91', '20,21,23,33(again)']
2024-03-06 -> ['73,76,79(again),91', '55(again),56,62,70', '1,3,5,4,19']
2024-03-05 -> ['73,76,79(again),91', '55(again),56,62,70', '39,48(again),49,53,54']
2024-03-04 -> ['55(again),56,62,70', '20,21,23,33(again)']
2024-03-03 -> ['39,48(again),49,53,54', '1,3,5,4,19']
2024-03-02 -> ['39,48(again),49,53,54', '20,21,23,33(again)']
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package LeetCodeJava.DynamicProgramming;

// https://leetcode.com/problems/decode-ways/description/

public class DecodeWays {

// V0
// IDEA : DP
// TODO : implement

// V1
// IDEA : DP
// https://leetcode.com/problems/decode-ways/solutions/4456554/character-state-machine-video-solution-java-c/
public int numDecodings(String encodedString) {
char s[] = encodedString.toCharArray();
if(s[0] == '0')return 0;
int sz = s.length;
int noWaysAtIndx[] = new int[sz];
noWaysAtIndx[0] = 1;
for(int indx = 1; indx < sz; indx++){
char currC = s[indx], prevC = s[indx-1];
if(currC == '0' && !(prevC == '1' || prevC == '2')){
return 0;
}
int onesDigit = currC - '0', tensDigit = prevC - '0';
int number = tensDigit * 10 + onesDigit;
if(number >= 10 && number <= 26){
if(indx >= 2)
noWaysAtIndx[indx] += noWaysAtIndx[indx-2];
else
noWaysAtIndx[indx] = 1;
}
if(number != 10 && number != 20){
noWaysAtIndx[indx] += noWaysAtIndx[indx-1];
}
}
return noWaysAtIndx[sz - 1];
}

// V2
// IDEA : DP
// https://leetcode.com/problems/decode-ways/solutions/4454539/decode-ways-java/
public int numDecodings_1(String s) {
int n = s.length();
int[] dp = new int[n + 1];
if(n == 0 || s.charAt(0) == '0') return 0;
dp[0] = 1; dp[1] = 1;

for(int i = 2; i <= n; i++){
// check for single-digit
if(s.charAt(i - 1) >= '1' && s.charAt(i - 1) <= '9') dp[i] = dp[i - 1];

// check for two-digits
if(s.charAt(i - 2) == '1') dp[i] += dp[i - 2];
else if(s.charAt(i - 2) == '2' && s.charAt(i - 1) >= '0' && s.charAt(i - 1) <= '6') dp[i] += dp[i - 2];
}
return dp[n];
}



}

0 comments on commit 2a7f3c4

Please sign in to comment.