Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Feb 28, 2024
1 parent 6de37b3 commit 83629cb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 36 deletions.
1 change: 1 addition & 0 deletions data/progress.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
20240228: 20,21
20240227: 1,3,5,4,19
20231218: 57(todo),58(todo),268,61(todo),297
20231211: 39,53,48,56
Expand Down
11 changes: 9 additions & 2 deletions data/to_review.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
2024-04-23 -> ['20,21']
2024-04-22 -> ['1,3,5,4,19']
2024-04-02 -> ['20,21']
2024-04-01 -> ['1,3,5,4,19']
2024-03-20 -> ['20,21']
2024-03-19 -> ['1,3,5,4,19']
2024-03-12 -> ['20,21']
2024-03-11 -> ['1,3,5,4,19']
2024-03-07 -> ['20,21']
2024-03-06 -> ['1,3,5,4,19']
2024-03-04 -> ['20,21']
2024-03-03 -> ['1,3,5,4,19']
2024-03-01 -> ['1,3,5,4,19']
2024-02-29 -> ['1,3,5,4,19']
2024-03-02 -> ['20,21']
2024-03-01 -> ['20,21', '1,3,5,4,19']
2024-02-29 -> ['20,21', '1,3,5,4,19']
2024-02-28 -> ['1,3,5,4,19']
2024-02-11 -> ['57(todo),58(todo),268,61(todo),297']
2024-02-04 -> ['39,53,48,56']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,40 @@

public class ValidParentheses {

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

if (s.length() % 2 != 0){
return false;
}

HashMap<String, String> map = new HashMap<>();
Stack st = new Stack();

map.put("(", ")");
map.put("{", "}");
map.put("[", "]");

for (int i = 0; i < s.length(); i++){
String cur = String.valueOf(s.charAt(i));
if (st.empty() && !map.containsKey(cur)){
return false;
}
if (map.containsKey(cur)){
st.push(cur);
}
else{
String popElement = (String) st.pop();
String expect = map.get(popElement);
if (!expect.equals(cur)){
return false;
}
}
}
return true ? st.empty() : false;
}

// V0'
// IDEA : STACK + add "inverse" Parentheses to stack directly
// https://www.bilibili.com/video/BV1AF411w78g/?share_source=copy_web&vd_source=771d0eba9b524b4f63f92e37bde71301
Expand Down Expand Up @@ -51,40 +85,6 @@ else if (cur.equals("[")){
return true ? st.empty() : false;
}

// V0
// IDEA : STACK
public boolean isValid(String s) {

if (s.length() % 2 != 0){
return false;
}

HashMap<String, String> map = new HashMap<>();
Stack st = new Stack();

map.put("(", ")");
map.put("{", "}");
map.put("[", "]");

for (int i = 0; i < s.length(); i++){
String cur = String.valueOf(s.charAt(i));
if (st.empty() && !map.containsKey(cur)){
return false;
}
if (map.containsKey(cur)){
st.push(cur);
}
else{
String popElement = (String) st.pop();
String expect = map.get(popElement);
if (!expect.equals(cur)){
return false;
}
}
}
return true ? st.empty() : false;
}

// V1
// https://leetcode.com/problems/valid-parentheses/solutions/3398779/python-java-c-simple-solution-video-solution/
public boolean isValid_1(String s) {
Expand Down

0 comments on commit 83629cb

Please sign in to comment.