Generate Parentheses LeetCode solution in Java
1class Solution {2List<String> s = new ArrayList<>();34public void get(int n, int x, String p) {5if (n == 0 && x == 0) {6s.add(p);7return;8}9if (n == 0) {10get(n, x - 1, p + ")");11} else if (x == 0) {12get(n - 1, x + 1, p + "(");13} else {14get(n, x - 1, p + ")");15get(n - 1, x + 1, p + "(");16}17}1819public List<String> generateParenthesis(int n) {20s.clear();21get(n, 0, "");22return s;23}24}