原创转载请注明出处:http://agilestyle.iteye.com/blog/2360764
Given Three pairs of "((()))"
Print "()()(), (())(), ()(()), ((()))"
核心思想:递归
package org.fool.java.test; public class ParenthesisPrintTest { public static void main(String[] args) { printParenthesis(3, 3, ""); } // left and right remains are keeping track of how many remaining parenthesis left for printing // currentString is used to keep track of the current printout for each recursive call private static void printParenthesis(int leftRemain, int rightRemain, String currentString) { if (rightRemain == 0) { System.out.println(currentString); return; } if (leftRemain > 0) { // more left parenthesis left for printing printParenthesis(leftRemain - 1, rightRemain, currentString + "("); if (leftRemain < rightRemain) { // which means more left parenthesis have been used printParenthesis(leftRemain, rightRemain - 1, currentString + ")"); } } else { // now there are only right parenthesis left printParenthesis(leftRemain, rightRemain - 1, currentString + ")"); } } }
Console Output
Reference
https://www.youtube.com/watch?v=_Uq1dmgZj0I&list=PLlhDxqlV_-vkak9feCSrnjlrnzzzcopSG&index=48
相关推荐
### 标题:Combinations of Intelligent Methods and Application #### 栈意与重点 该书的标题表明其主要内容是探讨不同智能方法的结合以及这些结合在实际中的应用。智能方法可以包括人工智能的各种子领域和技术,...
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephon
sioned expression (which in turn is based on the notion of data provenance), namely an expression that captures, in a compact way, the analysis result with respect to all possible combinations of ...
大师Donald E. Knuth(汉名高德纳)的著作,计算机程序设计与艺术第四卷3册:生成所有组合和分划Generating All Combinations and Permutations(中英)
**标题**:“The fantastic combinations of John Conway's new solitaire game life.pdf” **描述**:马丁·加德纳撰写的关于生命游戏的文章,希望对大家有所帮助。 本文档主要介绍了数学家约翰·康威(John ...
《计算机程序设计艺术》(The Art of Computer Programming)是由美国著名计算机科学家唐纳德·克努特(Donald E. Knuth)编写的经典著作,该系列书籍在计算机科学领域具有里程碑式的意义。此系列不仅涵盖了广泛的...
c c语言_leetcode 0017_letter_combinations_of_a_phone_number.zip
differences (JNDs) for the average observer and scene, transformations for different combinations of observer sensitivity and scene susceptibility were derived. The psychophysical results were used to...
java入门 java_leetcode题解之17_Letter_Combinations_of_a_Phone_Number
js js_leetcode题解之17-letter-combinations-of-a-phone-number.js
c语言入门 C语言_leetcode题解之17-letter-combinations-of-a-phone-number.c
proper combinations of threshold level and enhanced vaccination rate based on threshold policy can lead disease prevalence to a previously chosen level if eradication of disease is impossible.
// From a total of seven elements i want all combinations of groups having 5 elements. var allElements = [ "44" , "16" , "49" , "53" , "04" , "52" , "39" ] ; var outputList = smartCombin . combine ( ...
Letter Combinations of a Phone Number"这个项目,它涉及到如何通过JavaScript实现电话号码数字到字母的映射。 首先,让我们理解这个问题的基本概念。电话号码通常使用数字来表示,但为了方便记忆,这些数字往往...
MAKEBITS - 生成 N 位的位数组,其中包含 1 和 0 的所有组合。 示例:makebits(3)' 产生 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 但当然你可以把它翻转到横向。 我用它来测试通信渠道。
2. **Linear Statistics**: This refers to the statistical analysis of linear combinations of the transmission eigenvalues. Linear statistics provide a powerful tool for understanding the universal ...
17. Letter Combinations of a Phone Number 18. 4Sum 19. Remove Nth Node From End of List 20. Valid Parentheses 21. Merge Two Sorted Lists 22. Generate Parentheses 23. Merge k Sorted Lists 24. Swap ...