leetcode 22. Generate Parentheses #python

本題之前一直糾結如何循環調用,後來看網上思路有人用到遞歸,整理後的代碼如下, 基本思路是: 1.左邊括號數要大於右邊括號數 2.在1的原則下,每次遞歸爲字符串賦值"("或")" 3.每次遞歸生成兩個分支,分別往下去找,最終找到所有組合 Given n pairs of parentheses, write a function to generate all combinations of wel
相關文章
相關標籤/搜索