-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
39 lines (33 loc) · 1009 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
namespace CSProblems
{
class AllValidParenthesis
{
public static void Main()
{
Console.WriteLine("Find all combination of paranthesis for given value N");
int n = 8;
ValidParenthisis(n / 2, n / 2, string.Empty);
Console.ReadLine();
}
static void ValidParenthisis(int openParenthesis, int closedParanthesis, string result)
{
if (openParenthesis == 0 && closedParanthesis == 0)
{
Console.WriteLine(result);
}
if (openParenthesis > closedParanthesis)
{
return;
}
if (openParenthesis > 0)
{
ValidParenthisis(openParenthesis - 1, closedParanthesis, result + "(");
}
if (closedParanthesis > 0)
{
ValidParenthisis(openParenthesis, closedParanthesis - 1, result + ")");
}
}
}
}