zoukankan      html  css  js  c++  java
  • [LeetCode] 22

    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:

    "((()))", "(()())", "(())()", "()(())", "()()()"

    class Solution {
    public:
      void doGenerate(int x0, int x1, string&& s) {
        if (!x0 && !x1) {
          m_result.emplace_back(s);
        }
        if (x0 > 0) {
          doGenerate(x0 -1, x1, s + "(");
        }
        if (x1 > 0 && x1 > x0) {
          doGenerate(x0, x1 - 1 , s + ")");
        }
      }

      vector<string> generateParenthesis(int n) {
        int x0 = n, x1 = n;
        m_result.clear();
        doGenerate(n, n, "");
        return m_result;
      }
    private:
      vector<string> m_result;
    };

  • 相关阅读:
    Docker 镜像
    Docker 安装命令
    Docker 基本概念
    Redis 高可用之"持久化"
    Git 安装和使用
    oracle角色
    oracle权限
    审计
    手动创建数据库
    oracle口令文件认证
  • 原文地址:https://www.cnblogs.com/shoemaker/p/4769202.html
Copyright © 2011-2022 走看看