Skip to content

Commit

Permalink
update 20 java, cheatsheet, progress
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed May 27, 2024
1 parent 3b718af commit fbf7bb9
Show file tree
Hide file tree
Showing 5 changed files with 87 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 @@
20240527: 21
20240527: 21,20
20240526: 417(again),33,153,152
20240525: 424,297(todo),295(todo),39
20240524: 55,54(todo),53(again),435(again),49,48(todo),300(again)
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-21 -> ['21']
2024-07-21 -> ['21,20']
2024-07-20 -> ['417(again),33,153,152']
2024-07-19 -> ['424,297(todo),295(todo),39']
2024-07-18 -> ['55,54(todo),53(again),435(again),49,48(todo),300(again)']
Expand All @@ -16,7 +16,7 @@
2024-07-06 -> ['371']
2024-07-05 -> ['121,252']
2024-07-04 -> ['125']
2024-06-30 -> ['21']
2024-06-30 -> ['21,20']
2024-06-29 -> ['417(again),33,153,152']
2024-06-28 -> ['424,297(todo),295(todo),39']
2024-06-27 -> ['55,54(todo),53(again),435(again),49,48(todo),300(again)']
Expand All @@ -29,27 +29,27 @@
2024-06-20 -> ['347,253(todo),91(todo),217']
2024-06-19 -> ['226,98,253(todo)']
2024-06-18 -> ['104,230,102,100']
2024-06-17 -> ['21', '105,106']
2024-06-17 -> ['21,20', '105,106']
2024-06-16 -> ['417(again),33,153,152', '242,235']
2024-06-15 -> ['424,297(todo),295(todo),39', '371']
2024-06-14 -> ['55,54(todo),53(again),435(again),49,48(todo),300(again)', '121,252']
2024-06-13 -> ['56', '125']
2024-06-12 -> ['62,572,57']
2024-06-11 -> ['322,191,190']
2024-06-10 -> ['73,200,70,323(again)']
2024-06-09 -> ['21', '207,79,206,213,198']
2024-06-09 -> ['21,20', '207,79,206,213,198']
2024-06-08 -> ['417(again),33,153,152', '212(todo),211,338,208(again)']
2024-06-07 -> ['424,297(todo),295(todo),39', '347,253(todo),91(todo),217']
2024-06-06 -> ['55,54(todo),53(again),435(again),49,48(todo),300(again)', '226,98,253(todo)']
2024-06-05 -> ['56', '104,230,102,100']
2024-06-04 -> ['21', '62,572,57', '105,106']
2024-06-04 -> ['21,20', '62,572,57', '105,106']
2024-06-03 -> ['417(again),33,153,152', '322,191,190', '242,235']
2024-06-02 -> ['424,297(todo),295(todo),39', '73,200,70,323(again)', '371']
2024-06-01 -> ['21', '55,54(todo),53(again),435(again),49,48(todo),300(again)', '207,79,206,213,198', '121,252']
2024-06-01 -> ['21,20', '55,54(todo),53(again),435(again),49,48(todo),300(again)', '207,79,206,213,198', '121,252']
2024-05-31 -> ['417(again),33,153,152', '56', '212(todo),211,338,208(again)', '125']
2024-05-30 -> ['21', '424,297(todo),295(todo),39', '62,572,57', '347,253(todo),91(todo),217']
2024-05-29 -> ['21', '417(again),33,153,152', '55,54(todo),53(again),435(again),49,48(todo),300(again)', '322,191,190', '226,98,253(todo)']
2024-05-28 -> ['21', '417(again),33,153,152', '424,297(todo),295(todo),39', '56', '73,200,70,323(again)', '104,230,102,100']
2024-05-30 -> ['21,20', '424,297(todo),295(todo),39', '62,572,57', '347,253(todo),91(todo),217']
2024-05-29 -> ['21,20', '417(again),33,153,152', '55,54(todo),53(again),435(again),49,48(todo),300(again)', '322,191,190', '226,98,253(todo)']
2024-05-28 -> ['21,20', '417(again),33,153,152', '424,297(todo),295(todo),39', '56', '73,200,70,323(again)', '104,230,102,100']
2024-05-27 -> ['417(again),33,153,152', '424,297(todo),295(todo),39', '55,54(todo),53(again),435(again),49,48(todo),300(again)', '62,572,57', '207,79,206,213,198', '105,106']
2024-05-26 -> ['424,297(todo),295(todo),39', '55,54(todo),53(again),435(again),49,48(todo),300(again)', '56', '322,191,190', '212(todo),211,338,208(again)', '242,235']
2024-05-25 -> ['55,54(todo),53(again),435(again),49,48(todo),300(again)', '56', '62,572,57', '73,200,70,323(again)', '347,253(todo),91(todo),217', '371']
Expand Down
10 changes: 10 additions & 0 deletions doc/cheatsheet/java_trick.md
Original file line number Diff line number Diff line change
Expand Up @@ -709,4 +709,14 @@ return check_(root, smallest_val, biggest_val);

// LC 338

```

### 2-5) Init Queue

- https://stackoverflow.com/questions/4626812/how-do-i-instantiate-a-queue-object-in-java

- A Queue is an `interface`, which means you cannot construct a Queue directly.
- Consinder use one of below implementation:
```
AbstractQueue, ArrayBlockingQueue, ArrayDeque, ConcurrentLinkedQueue, DelayQueue, LinkedBlockingQueue, LinkedList, PriorityBlockingQueue, PriorityQueue, or SynchronousQueue.
```
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// https://www.softwaretestinghelp.com/java-queue-interface/

import java.util.HashMap;
import java.util.Map;
import java.util.Stack;

public class ValidParentheses {
Expand All @@ -13,6 +14,40 @@ public class ValidParentheses {
// IDEA : STACK + DICT
public boolean isValid(String s) {

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

Map<String, String> map = new HashMap<>();
map.put("(", ")");
map.put("{", "}");
map.put("[", "]");

/** NOTE !!! use stack here, FILO */
Stack<String> stack = new Stack<>();

for (String x : s.split("")){
//System.out.println("x = " + x + " stack = " + stack);
if (map.containsKey(x)){
stack.add(x);
}else{
if (stack.isEmpty()){
return false;
}
String last = stack.pop();
if (!map.get(last).equals(x)){
return false;
}
}
}

return stack.isEmpty();
}

// V0'
// IDEA : STACK + DICT
public boolean isValid_0(String s) {

if (s.length() % 2 != 0){
return false;
}
Expand Down
32 changes: 32 additions & 0 deletions leetcode_java/src/main/java/dev/workspace3.java
Original file line number Diff line number Diff line change
Expand Up @@ -2312,4 +2312,36 @@ public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
return root.next;
}

// LC 20
public boolean isValid(String s) {

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

Map<String, String> map = new HashMap<>();
map.put("(", ")");
map.put("{", "}");
map.put("[", "]");

Stack<String> stack = new Stack<>(); // TODO : check

for (String x : s.split("")){
System.out.println("x = " + x + " stack = " + stack);
if (map.containsKey(x)){
stack.add(x);
}else{
if (stack.isEmpty()){
return false;
}
String last = stack.pop();
if (!map.get(last).equals(x)){
return false;
}
}
}

return stack.isEmpty();
}

}

0 comments on commit fbf7bb9

Please sign in to comment.