Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fd45882

Browse files
committed
practice yield
1 parent d278cc5 commit fd45882

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

‎22_generate_parentheses.scala‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
object Solution {
2+
def generateParenthesis(n: Int): List[String] = {
3+
if (n == 0){
4+
List("")
5+
}else{
6+
val candidates = for {
7+
i <- 0 to (n - 1);
8+
s1 <- generateParenthesis(i);
9+
s2 <- generateParenthesis(n - i - 1)
10+
} yield "(" + s1 + ")" + s2
11+
candidates.toList
12+
}
13+
}
14+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /