In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to use leetcode20. Valid parentheses". In daily operation, I believe many people are using leetcode20. There are doubts on the issue of valid parentheses. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation, hoping to help you answer the doubts about "how to use leetcode20. Valid parentheses"! Next, please follow the editor to study!
1. Concept introduction
Stack, also known as stack, is an important data structure. From the point of view of data structure, stack is also a linear table, and its particularity lies in that the basic operation of stack is a subset of linear table operation, and it is a linear table with limited operation, so it can be called limited data structure. Restrict it to insert or delete only at the end of the table. The end of the table is called the top of the stack, and accordingly, the header is called the bottom of the stack. The basic operation of the stack not only inserts and deletes at the top of the stack, but also initializes the stack, determines the emptiness and takes the top elements of the stack and so on.
two。 Topic description
Given a string that includes only'(',')','{','}','[',']', determine whether the string is valid.
A valid string must satisfy:
The left parenthesis must be closed with the same type of closing parenthesis.
The left parenthesis must be closed in the correct order.
Note that an empty string can be considered a valid string.
Example 1:
Enter: "()"
Output: true
Example 2:
Enter: "() [] {}"
Output: true
Example 3:
Enter: "(]"
Output: false
Example 4:
Enter: "([)]"
Output: false
Example 5:
Enter: "{[]}"
Output: true
Source: power buckle (LeetCode)
Link: https://leetcode-cn.com/problems/valid-parentheses
3. Solution 1, stack 1, traversal string 2, press stack 3 when left symbol, compare stack with current character when right match, return false4 if not equal, end traversal time, return false if stack is not empty, otherwise return true*/4. Test result
Solution 1. Stack
5. Stack / * title: leetcode20. Valid parentheses author: xidoublestarmethod: stack type: Cdate: 2020-5-29*/bool isValid (char* s) {if (! strlen (s)) return true; int s_len = strlen (s); char* mid = (char*) malloc (s_len); int top = 0; for (int I = 0; I < s_len) ) {if (s [I] = ='('| | s [I] = ='['| | s [I] = ='{') mid [top++] = s [I]; else if (s [I] = =')'& (! top | | mid [--top]! ='(') return false Else if (s [I] = =']'& (! top) | | mid [--top]! ='[') return false; else if (s [I] = ='}'& & (! top | | mid [- top]! ='{') return false;} free (mid); return top? False: true;} at this point, the study on "how to use leetcode20. Valid parentheses" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.