LeetCode算法入门- Generate Parentheses -day16

  1. 题目描述
    Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.

For example, given n = 3, a solution set is:

[
“((()))”,
“(()())”,
“(())()”,
“()(())”,
“()()()”
]

  1. 题目分析:给定一个数字n,列出所有合法的序列,条件是左括号个数要大于或等于右括号个数:使用递归来实现

  2. Java实现:

class Solution {public List<String> generateParenthesis(int n) {List<String> result = new ArrayList<>();helper(n,n,"",result);return result;}public static void helper(int left, int right, String tmp, List<String> result){if(left == 0 && right == 0){result.add(tmp);return ;}if(left < 0 || right < 0 || left > right){return ;}helper(left-1, right, tmp+"(",result);helper(left, right-1, tmp+")",result);}
}

LeetCode算法入门- Generate Parentheses -day16相关推荐

  1. LeetCode算法入门- Valid Parentheses -day11

    LeetCode算法入门- Valid Parentheses -day11 题目描述: Given a string containing just the characters '(', ')', ...

  2. LeetCode算法入门- Longest Valid Parentheses -day12

    LeetCode算法入门- Longest Valid Parentheses -day12 Given a string containing just the characters '(' and ...

  3. LeetCode算法入门- Implement strStr() -day22

    LeetCode算法入门- Implement strStr() -day22 题目描述 Implement strStr(). Return the index of the first occur ...

  4. LeetCode算法入门- Remove Duplicates from Sorted Array -day21

    LeetCode算法入门- Remove Duplicates from Sorted Array -day21 题目描述 Given a sorted array nums, remove the ...

  5. LeetCode算法入门- Remove Element -day20

    LeetCode算法入门- Remove Element -day20 1. 题目描述 Given an array nums and a value val, remove all instance ...

  6. LeetCode算法入门- Search Insert Position -day19

    LeetCode算法入门- Search Insert Position -day19 题目描述 Given a sorted array and a target value, return the ...

  7. LeetCode算法入门- Multiply Strings -day18

    LeetCode算法入门- Multiply Strings -day18 题目介绍 Given two non-negative integers num1 and num2 represented ...

  8. LeetCode算法入门- Remove Nth Node From End of List -day17

    LeetCode算法入门- Remove Nth Node From End of List -day17 题目解释: Given a linked list, remove the n-th nod ...

  9. LeetCode算法入门- Merge Two Sorted Lists -day15

    LeetCode算法入门- Merge Two Sorted Lists -day15 题目描述: Merge two sorted linked lists and return it as a n ...

最新文章

  1. 互联网大脑进化简史,华为云EI智能体加入-2018年7月新版
  2. 手机模拟位置实现精准位置营销效果分析
  3. 单片机原理及其应用——单片机控制8只发光二极管交替闪烁
  4. 《C++ Primer 5th》笔记(9 / 19):顺序容器
  5. C++学习之路 | PTA乙级—— 1043 输出PATest (20 分)(精简)
  6. 2个 string 日期比较
  7. 御用导航提示提醒_汽车导航,离线和在线哪个好用?两者的区别分析
  8. php钩子是啥意思,thinkphp钩子是什么意思
  9. nodejs接收前端formData数据
  10. linux配置maven环境变量
  11. 古代一些练外丹的资料
  12. 全球科学家公认的高效学习法——费曼学习法
  13. 每日一練06:javascript原生拖拽写的日食
  14. HEVC 、H.264与AVS2 视频压缩
  15. 【C++】虚函数与虚函数表
  16. ReXNet学习笔记 --- ReXNet: Diminishing Representational Bottleneck on Convolutional Neural Network
  17. linux 命令安装 wine,Wine安装使用(适用Linux Mint 19与Ubuntu 18.04下)
  18. 视频转图片序列 java_怎样才能把一段视频转换成序列图片文件
  19. 如何配置系统数据库服务器地址,如何配置系统数据库服务器地址
  20. Erro和Exception区别Throw和Throws的区别

热门文章

  1. Redis 键值过期操作
  2. 美团面试题 | JVM 堆内存溢出后,其他线程是否可继续工作?
  3. 漫画:什么是归并排序?
  4. NTFS USN的Create和工具代码汇总
  5. 字符串分割--java中String.split()用法
  6. TextArea里Placeholder换行问题
  7. 微信开发2之php网页授权登录
  8. mysql数据库关联练习_mysql数据库建立数据表的练习(附代码)
  9. 创宇技能表_知道创宇研发技能表 一
  10. 接口批量同步数据_千手接口平台+电商ERP,助德嵘大药房征战拼多多