Skip to content

Commit

Permalink
update java 125, progress
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed May 10, 2024
1 parent 3cd3f63 commit 90320f9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions data/progress.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
20240510: 125
20240314: 647
20240313: 338,347,371,417(again),424(again),435,572(again)
20240312: 297(again),300,322(again),323
Expand Down
9 changes: 9 additions & 0 deletions data/to_review.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
2024-07-04 -> ['125']
2024-06-13 -> ['125']
2024-05-31 -> ['125']
2024-05-23 -> ['125']
2024-05-18 -> ['125']
2024-05-15 -> ['125']
2024-05-13 -> ['125']
2024-05-12 -> ['125']
2024-05-11 -> ['125']
2024-05-07 -> ['338,347,371,417(again),424(again),435,572(again)']
2024-05-06 -> ['297(again),300,322(again),323']
2024-05-05 -> ['261(again!!!),268,269(again),271,295(again)']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,29 @@ public boolean isPalindrome(String s) {
return true;
}

StringBuilder sb = new StringBuilder();
for (int idx = 0; idx < s.length(); idx++){
if (Character.isLetterOrDigit(s.charAt(idx))){
sb.append(String.valueOf(s.charAt(idx)).toUpperCase());
}
}

// NOTE : should use equals (so compare value but not memory address)
/**
* The issue in your code is with the comparison of strings using ==.
* In Java, you should use the equals method to compare strings for equality.
* Here's the corrected code:
*/
return sb.toString().equals(sb.reverse().toString());
}

// V0'
public boolean isPalindrome_0(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))){
Expand Down
21 changes: 21 additions & 0 deletions leetcode_java/src/main/java/dev/workspace3.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@ public static void main(String[] args) {
for (ThreadInfo threadInfo : threadInfos) {
System.out.println("[" + threadInfo.getThreadId() + "] " + threadInfo.getThreadName());
}
}

// LC 125
public boolean isPalindrome(String s) {

if (s == null || s.length() == 0){
return true;
}
String s_updated = "";
StringBuilder sb = new StringBuilder();
//String[] s_split = s.split(",");
char[] array = s.toCharArray();
for (char x : array){
String x_ = Character.toString(x);
if (x_ != null && x_ != "" && Character.isAlphabetic(x)){
sb.append(x_.toLowerCase());
}
}

System.out.println(sb.toString());
return sb.toString() == sb.reverse().toString();
}

}

0 comments on commit 90320f9

Please sign in to comment.