当前位置:网站首页>301. delete invalid brackets
301. delete invalid brackets
2022-06-23 07:08:00 【Graduation_ Design】
Preface
C++ It's a high-level programming language , from C Language expansion and upgrading , As early as 1979 By Benjani · Strauss LUP is AT&T Developed by Bell studio .
C++ Both can be carried out C Process programming of language , It can also be used for object-based programming characterized by abstract data types , It can also carry out object-oriented programming characterized by inheritance and polymorphism .C++ Good at object-oriented programming at the same time , You can also do process based programming .
C++ Have the practical characteristics of computer operation , At the same time, it is also committed to improving the programming quality of large-scale programs and the problem description ability of programming languages .
Java Is an object-oriented programming language , Not only absorbed C++ The advantages of language , It's abandoned C++ The incomprehensible inheritance in 、 Concepts such as pointer , therefore Java Language has two characteristics: powerful and easy to use .Java As the representative of static object-oriented programming language , Excellent implementation of object-oriented theory , Allow programmers to do complex programming in an elegant way of thinking .
Java It's simple 、 object-oriented 、 Distributed 、 Robustness, 、 Security 、 Platform independence and portability 、 Multithreading 、 Dynamic and so on .Java Can write desktop applications 、Web Applications 、 Distributed system and embedded system applications, etc .
Python By Guido of the Dutch Society for mathematical and computer science research · Van rosum On 1990 It was designed in the early 's , As a course called ABC A substitute for language .Python Provides efficient advanced data structure , It's also a simple and effective way of object-oriented programming .Python Syntax and dynamic types , And the nature of interpretative language , Make it a programming language for scripting and rapid application development on most platforms , With the continuous update of the version and the addition of new language features , Gradually used for independent 、 Development of large projects .
Python The interpreter is easy to extend , have access to C Language or C++( Or something else can be done through C Calling language ) Expand new functions and data types .Python It can also be used as an extensible programming language in customizable software .Python Rich library of standards , Provides source code or machine code for each major system platform .
2021 year 10 month , Compiler for language popularity index Tiobe take Python Crowned the most popular programming language ,20 Put it in... For the first time in years Java、C and JavaScript above .
describe
Here's a string of parentheses and letters s , Remove the minimum number of invalid parentheses , Make the input string valid .
Returns all possible results . You can press In any order return .
Example 1:
Input :s = "()())()"
Output :["(())()","()()()"]
Example 2:
Input :s = "(a)())()"
Output :["(a())()","(a)()()"]
Example 3:
Input :s = ")("
Output :[""]
class Solution {
private List<String> res = new ArrayList<String>();
public List<String> removeInvalidParentheses(String s) {
int lremove = 0;
int rremove = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == '(') {
lremove++;
} else if (s.charAt(i) == ')') {
if (lremove == 0) {
rremove++;
} else {
lremove--;
}
}
}
helper(s, 0, lremove, rremove);
return res;
}
private void helper(String str, int start, int lremove, int rremove) {
if (lremove == 0 && rremove == 0) {
if (isValid(str)) {
res.add(str);
}
return;
}
for (int i = start; i < str.length(); i++) {
if (i != start && str.charAt(i) == str.charAt(i - 1)) {
continue;
}
// If the remaining characters cannot meet the number of characters to be removed , Go straight back to
if (lremove + rremove > str.length() - i) {
return;
}
// Try to remove an open parenthesis
if (lremove > 0 && str.charAt(i) == '(') {
helper(str.substring(0, i) + str.substring(i + 1), i, lremove - 1, rremove);
}
// Try to remove a closing bracket
if (rremove > 0 && str.charAt(i) == ')') {
helper(str.substring(0, i) + str.substring(i + 1), i, lremove, rremove - 1);
}
}
}
private boolean isValid(String str) {
int cnt = 0;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == '(') {
cnt++;
} else if (str.charAt(i) == ')') {
cnt--;
if (cnt < 0) {
return false;
}
}
}
return cnt == 0;
}
}
边栏推荐
- Concepts and differences of DQL, DML, DDL and DCL
- 深度学习系列46:人脸图像超分GFP-GAN
- MySQL MVCC多版本并发控制
- Traversal of binary tree and related knowledge
- Swagger3 integrates oauth2 authentication token
- C # how to obtain DPI and real resolution (can solve the problem that has been 96)
- deeplab v3 代码结构图
- 【STL】容器适配器之stack、queue用法总结
- Side effects of threads in embedded real-time systems
- 20220621 Dual Quaternion
猜你喜欢

Analyzing the creation principle in maker Education

Xiaobai must see in investment and wealth management: illustrated fund buying and selling rules

Children's programming for comprehensively cultivating students' mental thinking

407 stack and queue (232. implementing queue with stack, 225. implementing stack with queue)

深度学习系列46:人脸图像超分GFP-GAN

Configuration and compilation of mingw-w64, msys and ffmpeg

EndNote20使用教程分享(未完

WPF command directive and inotifypropertychanged

Traversal of binary tree and related knowledge

406 double pointer (27. remove elements, 977. square of ordered array, 15. sum of three numbers, 18. sum of four numbers)
随机推荐
C # how to obtain DPI and real resolution (can solve the problem that has been 96)
318. maximum word length product
Cetos7 record
js 判断两个数组增加和减少的元素
[daily training] 513 Find the value in the lower left corner of the tree
Chrome remove duplicate bookmarks
What you need to know about five insurances and one fund
Page embedded iframe click browser back problem
C DPI adaptation problem
深度学习系列47:超分模型Real-ESRGAN
GloRe
XML schema record
306. 累加数
The illustration shows three handshakes and four waves. Xiaobai can understand them
898. 子数组按位或操作
746. climbing stairs with minimum cost - Dynamic Planning
【畢業季·進擊的技術er】自己的選擇,跪著也要走
数据在内存中的存储方式(C语言)
Endnote20 tutorial sharing (unfinished
309. 最佳买卖股票时机含冷冻期