代码随想录算法训练营第十一天 | 20. 有效的括号 1047. 删除字符串中的所有相邻重复项 150. 逆波兰表达式求值

20. 有效的括号 

Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

An input string is valid if:

Open brackets must be closed by the same type of brackets.

Open brackets must be closed in the correct order.

Every close bracket has a corresponding open bracket of the same type.

#1 自己看到题目的第一想法    

新建一个array,用pop和push即可解决。就是如果array是空的时候需要单独的处理一下。

#2 看完代码随想录之后的想法   

由于栈结构的特殊性,非常适合做对称匹配类的题目。

1047. 删除字符串中的所有相邻重复项 

You are given a string s consisting of lowercase English letters. A duplicate removal consists of choosing two adjacent and equal letters and removing them.

We repeatedly make duplicate removals on s until we no longer can.

Return the final string after all such duplicate removals have been made. It can be proven that the answer is unique.

#1 自己看到题目的第一想法 

同上题

150. 逆波兰表达式求值 

#1 自己看到题目的第一想法    

同上题

#2 收获    

这几道题都非常的类似,都是新建一个stack,然后比较当前的元素和stack.pop(),难度不难,写的时候注意一些细节就好

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容