Skip to content

Commit

Permalink
update progress, cheatsheet
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed May 13, 2024
1 parent 04cd32d commit 076cddb
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 12 deletions.
1 change: 1 addition & 0 deletions data/progress.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
20240513: 242
20240512: 371
20240511: 121,252
20240510: 125
Expand Down
13 changes: 9 additions & 4 deletions data/to_review.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
2024-07-07 -> ['242']
2024-07-06 -> ['371']
2024-07-05 -> ['121,252']
2024-07-04 -> ['125']
2024-06-16 -> ['242']
2024-06-15 -> ['371']
2024-06-14 -> ['121,252']
2024-06-13 -> ['125']
2024-06-03 -> ['242']
2024-06-02 -> ['371']
2024-06-01 -> ['121,252']
2024-05-31 -> ['125']
2024-05-26 -> ['242']
2024-05-25 -> ['371']
2024-05-24 -> ['121,252']
2024-05-23 -> ['125']
2024-05-21 -> ['242']
2024-05-20 -> ['371']
2024-05-19 -> ['121,252']
2024-05-18 -> ['125']
2024-05-18 -> ['242', '125']
2024-05-17 -> ['371']
2024-05-16 -> ['121,252']
2024-05-15 -> ['371', '125']
2024-05-14 -> ['371', '121,252']
2024-05-16 -> ['242', '121,252']
2024-05-15 -> ['242', '371', '125']
2024-05-14 -> ['242', '371', '121,252']
2024-05-13 -> ['371', '121,252', '125']
2024-05-12 -> ['121,252', '125']
2024-05-11 -> ['125']
Expand Down
6 changes: 4 additions & 2 deletions doc/cheatsheet/java_trick.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ Collections.reverse(levels);

### 1-0-4) Reverse String
```java
// java
// java (via StringBuilder)
// LC 567

private String reverseString(String input){

if (input.equals(null) || input.length() == 0){
Expand All @@ -162,7 +163,8 @@ private String reverseString(String input){

### 1-0-5) Access elements in a String
```java
// java
// java (via .split(""))

String word = "heloooo 123 111";
for (String x : word.split("")){
System.out.println(x);
Expand Down
11 changes: 11 additions & 0 deletions doc/cheatsheet/string.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ In [12]: a_array
Out[12]: ['1', '2', '3', '4']
```

```java
// java
// split string (java)
/** NOTE !!! split string via .split("") */

for (String x : s.split("")){
System.out.println(x);
}
```


#### 1-8) Group sub-string
```python
# LC 696. Count Binary Substrings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public boolean isAnagram(String s, String t) {
if (s == null && t == null){
return true;
}
// if ((s == null && t != null) || (s != null && t == null) ){
// return false;
// }

Map<String, Integer> sMap = new HashMap<>();

/** NOTE !!! split string via .split("") */
for (String x : s.split("")){
if (!sMap.containsKey(x)){
sMap.put(x, 1);
Expand Down
49 changes: 46 additions & 3 deletions leetcode_java/src/main/java/dev/workspace3.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;

// https://javaguide.cn/java/concurrent/java-concurrent-questions-01.html#%E4%BD%95%E4%B8%BA%E7%BA%BF%E7%A8%8B

Expand Down Expand Up @@ -174,5 +172,50 @@ public String multiplyStr(String str, int multiplier){
return sb.toString();
}

// LC 242
public boolean isAnagram(String s, String t) {

if (s == null && t == null){
return true;
}

if (s == null || t == null){
return false;
}

Map<String, Integer> map = new HashMap();
char[] s_array = s.toCharArray();
char[] t_array = t.toCharArray();

for (char x : s_array){
String cur = String.valueOf(x);
if (!map.containsKey(cur)) {
map.put(cur, 1);
}else{
map.put(cur, map.get(cur)+1);
}
}

for (char y: t_array){
String cur = String.valueOf(y);
if (!map.containsKey(cur)) {
return false;
}else{
map.put(cur, map.get(cur)-1);
if (map.get(cur) == 0){
map.remove(cur);
}
}
}

System.out.println("map = " + map);

if (map.keySet().size() != 0){
return false;
}

return true;
}


}

0 comments on commit 076cddb

Please sign in to comment.