package question;import java.util.LinkedList;import java.util.List;public class Question22 {public static void main(String[] args) {}List<String> res = new LinkedList<>();public List<String> generateParenthesis(int n) {if (n==0) return res;char[] chars = new char[n<<1];huiSu(chars, n, new int[]{n, n}, 0);return res;}public void huiSu(char[] chars, int n, int[] t, int i) {if (i==n*2) {res.add(String.valueOf(chars));return;}if (t[0]<t[1]) {t[1]--;chars[i]=')';i++;huiSu(chars, n, t, i);i--;t[1]++;}if (t[0]>0) {t[0]--;chars[i]='(';i++;huiSu(chars, n, t, i);t[0]++;}}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。