Skip to content

Commit

Permalink
add lc company, update progress
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Jun 10, 2024
1 parent 3e47a2e commit 03b4171
Show file tree
Hide file tree
Showing 126 changed files with 1,291 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 @@
20240610:
20240609: 236(again*),1448(again),needcode_trie,208(ok*),needcode_graph,695,22(todo),981(todo),207(todo),261(todo)
20240608: 503(todo),739(ok),105(todo),needcode_heap_pq,1046,215,needcode_backtrack,78,39(todo),46,90(todo),77
20240607: 235(ok),236(again),496(ok),110(ok),1448(again!)
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1,176 changes: 1,176 additions & 0 deletions doc/Leetcode_company_frequency-master/README.md

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
27 changes: 27 additions & 0 deletions leetcode_java/src/main/java/dev/workSpace4.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,33 @@ public static void main(String[] args) {
workSpace4 wp = new workSpace4();
wp.myFunc();


System.out.println("isValidP test --------------");
String mystr = "(())"; //"()))";
System.out.println(wp.isValidP(mystr));

}

public boolean isValidP(String input){
System.out.println("---> input = " + input);
if (input.length() == 0){
return true;
}
// leftCnt : "(" count
// rightCnt : ") count
int leftCnt = 0;
int rightCnt = 0;
for (String x : input.split("")){
if (x.equals("(")){
leftCnt += 1;
}else{
rightCnt += 1;
}
if (rightCnt > leftCnt){
return false;
}
}
return true;
}

private void myFunc(){
Expand Down
87 changes: 87 additions & 0 deletions leetcode_java/src/main/java/dev/workspace3.java
Original file line number Diff line number Diff line change
Expand Up @@ -4804,5 +4804,92 @@ public void getBiggestArea(int x, int y, int[][] grid, int curArea) {
//return curArea;
}

// LC 22
// IDEA : Backtrack
// 1 <= n <= 8
// 3.30
List<String> res_ = new ArrayList<>();
public List<String> generateParenthesis2(int n) {

//List<String> res = new ArrayList<>();
if (n == 1){
this.res_.add("(");
this.res_.add(")");
return this.res_;
}

// backtrack
String cur = "";
this.getParenthesis_(n, cur);
System.out.println("this.res_ = " + this.res_);
return this.res_;
}

// leftCnt : "(" count
// rightCnt : ") count
public void getParenthesis_(int n, String cur) {

if (cur.length() > 2 * n){
return;
}

if (isValidP(cur.toString()) && cur.toString().length() == 2 * n) {
if (!this.res_.contains(cur)) {
this.res_.add(cur);
cur = ""; // ?
return;
}
}

String[] choices = {"(", ")"};
StringBuilder sb = new StringBuilder(cur);
for (String c : choices) {
/**
* 2 conditions
*
* 1) leftCnt > rightCnt
* 2) 1st element must be "("
*
*/
// case 1) invalid string
if (!isValidP(cur)) {
return;
}

// case 2) cur is null
if (sb.length() == 0) {
sb.append("(");
}else{
// case 3) OK to append "(" or ")"
sb.append(c);
}
// undo
this.getParenthesis_(n, sb.toString());
sb.deleteCharAt(sb.length() - 1);
}
}

public boolean isValidP(String input){
if (input.length() == 0){
return true;
}
// leftCnt : "(" count
// rightCnt : ") count
int leftCnt = 0;
int rightCnt = 0;
for (String x : input.split("")){
if (x.equals("(")){
leftCnt += 1;
}else{
rightCnt += 1;
}
if (rightCnt > leftCnt){
return false;
}
}
return true;
}



}

0 comments on commit 03b4171

Please sign in to comment.