Menghasilkan tanda kurung
class Solution {
List<String> generateParentheses(int n) {
List<String> result = new ArrayList<>();
if (n == 0) {
String empty = "";
result.add(empty);
}
else {
for (int closure = 0; closure < n; closure++)
for (String left: generateParentheses(closure))
for (String right: generateParentheses(n - closure - 1))
result.add("(" + left + ")" + right);
}
return result;
}
}
Enchanting Eagle