Tag Archives: parenthesis

Generate all combination of parenthesis

Given a number of pair parenthesis. Generate all combinations. For example n = 2, then should return ArrayList<String> = [“(())”, “()()”]; The solution is like below. public static ArrayList<String> generateParenthesis(int n) { // Write your code here ArrayList<String> list = new ArrayList<String>(); parenthesisHelper(0, 0, n, list, “”); return list; } public static void parenthesisHelper(int open,… Read More »