Tag Archives: combination

Factor Combination

leetcode 254. Numbers can be regarded as product of its factors. For example, 8 = 2 x 2 x 2; = 2 x 4. Write a function that takes an integer n and return all possible combinations of its factors. Note: Each combination’s factors must be sorted ascending, for example: The factors of 2 and 6… Read More »

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 »