@@ -0,0 +1,882 @@
+package leetcode.generate_parentheses;%0A%0Aimport java.util.ArrayList;%0A%0Apublic class Solution %7B%0A%09public static void dfs(int n, int depth, int stack, StringBuilder sb, ArrayList%3CString%3E ary)%7B%0A%09%09if(depth == 2 * n)%7B%0A%09%09%09ary.add(sb.toString());%0A%09%09%7Delse%7B%0A%09%09%09if(stack %3E 0)%7B%0A%09%09%09%09sb.append(')');%0A%09%09%09%09dfs(n, depth + 1, stack - 1, sb, ary);%0A%09%09%09%09sb.setLength(sb.length() - 1);%0A%09%09%09%7D%0A%09%09%09if(depth + stack %3C n * 2)%7B%0A%09%09%09%09sb.append('(');%0A%09%09%09%09dfs(n, depth + 1, stack + 1, sb, ary);%0A%09%09%09%09sb.setLength(sb.length() - 1);%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%09%0A    public ArrayList%3CString%3E generateParenthesis(int n) %7B%0A    %09ArrayList%3CString%3E ary = new ArrayList%3CString%3E();%0A        dfs(n, 0, 0, new StringBuilder(), ary);%0A        return ary;%0A    %7D%0A    %0A    public static void main(String%5B%5D args)%7B%0A    %09ArrayList%3CString%3E ans = new Solution().generateParenthesis(4);%0A    %09for(String s : ans)%7B%0A    %09%09System.err.println(s);%0A    %09%7D%0A    %7D%0A%7D%0A

Add java solution for 22. Generate Parentheses