Skip to content

Commit bbf6b0f

Browse files
committed
022 (3) update solution
1 parent 6a78bd8 commit bbf6b0f

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/_022_GenerateParentheses/Solution.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public List<String> generateParenthesis(int n) {
3232
return result;
3333
}
3434

35-
public void generateParenthesis(int n, int leftsUsed, int rightsUsed,
35+
private void generateParenthesis(int n, int leftsUsed, int rightsUsed,
3636
String prefix, List<String> result) {
3737
// base case
3838
if (leftsUsed == n && rightsUsed == n) {
@@ -43,18 +43,15 @@ public void generateParenthesis(int n, int leftsUsed, int rightsUsed,
4343
// recursive case
4444
if (leftsUsed == rightsUsed) {
4545
// next must be '("
46-
generateParenthesis(n, leftsUsed + 1, rightsUsed, prefix + "(",
47-
result);
46+
generateParenthesis(n, leftsUsed + 1, rightsUsed, prefix + "(", result);
4847
} else {
4948
// can either be "(" or ")"
5049
if (leftsUsed < n) {
5150
// still has "(" left for use
52-
generateParenthesis(n, leftsUsed + 1, rightsUsed, prefix + "(",
53-
result);
51+
generateParenthesis(n, leftsUsed + 1, rightsUsed, prefix + "(", result);
5452
}
5553
if (rightsUsed < n) {
56-
generateParenthesis(n, leftsUsed, rightsUsed + 1, prefix + ")",
57-
result);
54+
generateParenthesis(n, leftsUsed, rightsUsed + 1, prefix + ")", result);
5855
}
5956
}
6057
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy