Skip to content

Commit

Permalink
add 125 java, update progress
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Mar 6, 2024
1 parent ae91735 commit 32fa688
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@
058| [Length of Last Word](https://leetcode.com/problems/length-of-last-word/) | [Python](./leetcode_python/String/length-of-last-word.py) | _O(n)_ | _O(1)_ | Easy || OK
067| [Add Binary](https://leetcode.com/problems/add-binary/) | [Python](./leetcode_python/String/add-binary.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/String/AddBinary.java) | _O(n)_ | _O(1)_ | Easy | bit op, `good basic`, `fb`, `amazon`| OK***** (7) (but again)
076| [Minimum Window Substring](https://leetcode.com/problems/minimum-window-substring/) | [Python](./leetcode_python/String/minimum_window_substring.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/String/MinimumWindowSubstring.java) | | | Hard |`Curated Top 75` | AGAIN******* (2) (not start)
125| [Valid Palindrome](https://leetcode.com/problems/valid-palindrome/) | [Python](./leetcode_python/String/valid-palindrome.py) | _O(n)_ | _O(1)_ | Easy|Curated Top 75, LC 680, `amazon`,`fb`| OK
125| [Valid Palindrome](https://leetcode.com/problems/valid-palindrome/) | [Python](./leetcode_python/String/valid-palindrome.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/String/ValidPalindrome.java) | _O(n)_ | _O(1)_ | Easy|Curated Top 75, LC 680, `amazon`,`fb`| OK
151| [Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string/) | [Python](./leetcode_python/String/reverse-words-in-a-string.py) | _O(n)_ | _O(1)_ | Medium |`amazon`,`fb`| OK (2)
161| [One Edit Distance](https://leetcode.com/problems/one-edit-distance/) | [Python](./leetcode_python/String/one-edit-distance.py) | _O(m + n)_ | _O(1)_ | Medium |🔒, trick, recursion, string, , `fb`| AGAIN ******** (6)(AGAIN)
165| [Compare Version Numbers](https://leetcode.com/problems/compare-version-numbers/) | [Python](./leetcode_python/String/compare-version-numbers.py) | _O(n)_ | _O(1)_ |Medium|good basic, string,`amazon`, `apple`| OK** (5)
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 @@
20240306: 121,124(again)
20240306: 121,124(again),125
20240305: 100,102,104,105(again)
20240304: 73,76,79(again),91,25
20240303: 55(again),56,62,70
Expand Down
18 changes: 9 additions & 9 deletions data/to_review.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
2024-04-30 -> ['121,124(again)']
2024-04-30 -> ['121,124(again),125']
2024-04-29 -> ['100,102,104,105(again)']
2024-04-28 -> ['73,76,79(again),91,25']
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-09 -> ['121,124(again)']
2024-04-09 -> ['121,124(again),125']
2024-04-08 -> ['100,102,104,105(again)']
2024-04-07 -> ['73,76,79(again),91,25']
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-27 -> ['121,124(again)']
2024-03-27 -> ['121,124(again),125']
2024-03-26 -> ['100,102,104,105(again)']
2024-03-25 -> ['73,76,79(again),91,25']
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 -> ['121,124(again)', '1,3,5,4,19']
2024-03-19 -> ['121,124(again),125', '1,3,5,4,19']
2024-03-18 -> ['100,102,104,105(again)']
2024-03-17 -> ['73,76,79(again),91,25']
2024-03-16 -> ['55(again),56,62,70']
2024-03-14 -> ['121,124(again)']
2024-03-14 -> ['121,124(again),125']
2024-03-13 -> ['100,102,104,105(again)', '39,48(again),49,53,54']
2024-03-12 -> ['73,76,79(again),91,25', '20,21,23,33(again)']
2024-03-11 -> ['121,124(again)', '55(again),56,62,70', '1,3,5,4,19']
2024-03-11 -> ['121,124(again),125', '55(again),56,62,70', '1,3,5,4,19']
2024-03-10 -> ['100,102,104,105(again)']
2024-03-09 -> ['121,124(again)', '73,76,79(again),91,25']
2024-03-08 -> ['121,124(again)', '100,102,104,105(again)', '55(again),56,62,70', '39,48(again),49,53,54']
2024-03-07 -> ['121,124(again)', '100,102,104,105(again)', '73,76,79(again),91,25', '20,21,23,33(again)']
2024-03-09 -> ['121,124(again),125', '73,76,79(again),91,25']
2024-03-08 -> ['121,124(again),125', '100,102,104,105(again)', '55(again),56,62,70', '39,48(again),49,53,54']
2024-03-07 -> ['121,124(again),125', '100,102,104,105(again)', '73,76,79(again),91,25', '20,21,23,33(again)']
2024-03-06 -> ['100,102,104,105(again)', '73,76,79(again),91,25', '55(again),56,62,70', '1,3,5,4,19']
2024-03-05 -> ['73,76,79(again),91,25', '55(again),56,62,70', '39,48(again),49,53,54']
2024-03-04 -> ['55(again),56,62,70', '20,21,23,33(again)']
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package LeetCodeJava.String;

// https://leetcode.com/problems/valid-palindrome/description/?envType=list&envId=xoqag3yj

/**
* A phrase is a palindrome if, after converting all uppercase letters into lowercase
* letters and removing all non-alphanumeric characters,
* it reads the same forward and backward.
* Alphanumeric characters include letters and numbers.
*
*
* NOTE !!!
*
* "and removing all non-alphanumeric characters, "
* -> so we need to consider both alphabet and numeric element
*/

public class ValidPalindrome {

// V0
public boolean isPalindrome(String s) {

if (s == null || s.length() == 0){
return true;
}

String sUpper = "";
for (int idx = 0; idx < s.length(); idx++){
if (Character.isLetterOrDigit(s.charAt(idx))){
sUpper += String.valueOf(s.charAt(idx)).toUpperCase();
}
}

//System.out.println("sUpper = " + sUpper);
//String sUpper = s.toUpperCase();

// 2 pointer
int l = 0;
int r = sUpper.length() - 1;
while (r > l){
if (sUpper.charAt(l) != sUpper.charAt(r)){
return false;
}
l += 1;
r -= 1;
}
return true;
}

// V1
// https://leetcode.com/problems/valid-palindrome/solutions/4787889/simple-solution-using-java/?envType=list&envId=xoqag3yj
public boolean isPalindrome_1(String s) {
String str=s.replaceAll("[^a-zA-Z0-9]","").toLowerCase();
StringBuilder sb=new StringBuilder(str);
sb.reverse();
String ans=sb.toString();
for(int i=0;i<str.length();i++){
if(str.charAt(i)!=ans.charAt(i)){
return false;
}
}
return true;
}

}

0 comments on commit 32fa688

Please sign in to comment.