problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::remove_invalid_parentheses::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static bool isValid (const string &str)
 
static vector< string > removeInvalidParentheses (const string &s)
 

详细描述

在文件 leetcode.h3015 行定义.

成员函数说明

◆ isValid()

bool leetcode::remove_invalid_parentheses::Solution::isValid ( const string &  str)
static

在文件 leetcode.cpp8525 行定义.

8525 {
8526 int count = 0;
8527
8528 for(const char c: str) {
8529 if(c == '(') {
8530 count++;
8531 } else if(c == ')') {
8532 count--;
8533 if(count < 0) {
8534 return false;
8535 }
8536 }
8537 }
8538
8539 return count == 0;
8540 }

被这些函数引用 removeInvalidParentheses().

◆ removeInvalidParentheses()

vector< string > leetcode::remove_invalid_parentheses::Solution::removeInvalidParentheses ( const string &  s)
static

在文件 leetcode.cpp8496 行定义.

8496 {
8497 vector<string> ans;
8498 unordered_set<string> currSet;
8499
8500 currSet.insert(s);
8501 while(true) {
8502 for(auto &str: currSet) {
8503 if(isValid(str))
8504 ans.emplace_back(str);
8505 }
8506 if(!ans.empty()) {
8507 sort(ans.begin(), ans.end());
8508 return ans;
8509 }
8510 unordered_set<string> nextSet;
8511 for(auto &str: currSet) {
8512 for(int i = 0; i < str.size(); i++) {
8513 if(i > 0 && str[i] == str[i - 1]) {
8514 continue;
8515 }
8516 if(str[i] == '(' || str[i] == ')') {
8517 nextSet.insert(str.substr(0, i) + str.substr(i + 1, str.size()));
8518 }
8519 }
8520 }
8521 currSet = nextSet;
8522 }
8523 }
static bool isValid(const string &str)
Definition: leetcode.cpp:8525

引用了 isValid().

被这些函数引用 leetcode::remove_invalid_parentheses::TEST().


该类的文档由以下文件生成: