LeetCode-20.有效的括号(栈的使用+map的count)

本文介绍了一种使用栈和哈希表解决LeetCode-20题的有效括号问题。通过遍历字符串,遇到左括号入栈,遇到右括号时检查栈顶是否有匹配的左括号,最后栈为空则有效,否则无效。同时,讨论了map的count和find方法在查找元素时的区别。
摘要由CSDN通过智能技术生成

题目内容

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/valid-parentheses/

给定一个只包括 ‘(’,’)’,’{’,’}’,’[’,’]’ 的字符串 s ,判断字符串是否有效。

有效字符串需满足:
左括号必须用相同类型的右括号闭合。
左括号必须以正确的顺序闭合。

示例 1:

输入:s = "()"
输出:true

示例 2:

输入:s = "()[]{}"
输出:true

示例 3:

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
unordered_mapcount函数用于查找特定值在unordered_map中出现的次数。它的使用方式是通过调用unordered_mapcount函数,并传入要查找的值作为参数。返回值是找到的个数。 例如,如果我们有一个unordered_map<int, int> hashmap,并且其中包含键值对(1, 9),(2, 9),(3, 9),我们可以使用hashmap.count(1)来查找键为1的键值对的个数。在这个例子中,count函数将返回1,表示在unordered_map中存在一个键为1的键值对。同样地,我们也可以使用hashmap.count(5)来查找键为5的键值对的个数。在这个例子中,count函数将返回0,表示在unordered_map中不存在键为5的键值对。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [圆和矩形是否重叠leetcode-Algorithm-Notes:关于Leetcode、Lintcode编码问题的注意事项](https://download.csdn.net/download/weixin_38665775/19936221)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [unordered_map的find和count函数使用总结](https://blog.csdn.net/qq_33634666/article/details/116279227)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [unordered_map中find和count函数的区别](https://blog.csdn.net/qq_44879626/article/details/116192494)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_归尘_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值