首页 > 其他分享 >leetcode-栈=20

leetcode-栈=20

时间:2022-09-07 09:48:19浏览次数:82  
标签:false 示例 else 括号 20 stack leetcode


import java.util.ArrayList;
import java.util.Stack;

/**
<p>给定一个只包括 <code>'('</code>,<code>')'</code>,<code>'{'</code>,<code>'}'</code>,<code>'['</code>,<code>']'</code> 的字符串 <code>s</code> ,判断字符串是否有效。</p>

<p>有效字符串需满足:</p>

<ol>
	<li>左括号必须用相同类型的右括号闭合。</li>
	<li>左括号必须以正确的顺序闭合。</li>
</ol>

<p> </p>

<p><strong>示例 1:</strong></p>

<pre>
<strong>输入:</strong>s = "()"
<strong>输出:</strong>true
</pre>

<p><strong>示例 2:</strong></p>

<pre>
<strong>输入:</strong>s = "()[]{}"
<strong>输出:</strong>true
</pre>

<p><strong>示例 3:</strong></p>

<pre>
<strong>输入:</strong>s = "(]"
<strong>输出:</strong>false
</pre>

<p><strong>示例 4:</strong></p>

<pre>
<strong>输入:</strong>s = "([)]"
<strong>输出:</strong>false
</pre>

<p><strong>示例 5:</strong></p>

<pre>
<strong>输入:</strong>s = "{[]}"
<strong>输出:</strong>true</pre>

<p> </p>

<p><strong>提示:</strong></p>

<ul>
	<li><code>1 <= s.length <= 10<sup>4</sup></code></li>
	<li><code>s</code> 仅由括号 <code>'()[]{}'</code> 组成</li>
</ul>
<div><div>Related Topics</div><div><li>栈</li><li>字符串</li></div></div><br><div><li>

标签:false,示例,else,括号,20,stack,leetcode
From: https://www.cnblogs.com/xiaoshahai/p/16664181.html

相关文章

  • 1.HTML基础(2022-9-7)
                ......
  • P5999 [CEOI2016] kangaroo 题解
    感觉这样的\(\text{dp}\)题还比较多,思路都比较的神奇。个人感觉比较像区间\(\text{dp}\)的一类变种。但又和区间\(\text{dp}\)的维护方式极不一样。对于此类\(\t......
  • LeetCode 101 对称二叉树
    /***Definitionforabinarytreenode.*structTreeNode{*intval;*TreeNode*left;*TreeNode*right;*TreeNode():val(0),left(......
  • 2022.9.7 模拟
    挂了点分,原因如下:r=mid-1;mid=(l+r)/2;UnknownTLE(本地测没有超过0.7s)反正题不难。T3一眼原题,其实现做也会,就是缩点后的拓扑dp。然后做T2,T2读了题......
  • 如何解决leetcode挑战棒球比赛???
    如何解决leetcode挑战棒球比赛???你正在为一场规则奇怪的棒球比赛记分。游戏由几轮组成,过去几轮的得分可能会影响未来几轮的得分。相关文章:什么是链接列表以及如何通过面......
  • 磨练 LeetCode 问题的禅宗:第 93 天——缺失和多余的数字
    磨练LeetCode问题的禅宗:第93天——缺失和多余的数字欢迎回到LeetCode日常练习系列.今天我做了2简单问题。让我们开始!Photoby詹姆斯·萨顿on不飞溅单......
  • LeetCode 226 翻转二叉树
    /***Definitionforabinarytreenode.*structTreeNode{*intval;*TreeNode*left;*TreeNode*right;*TreeNode():val(0),left(......
  • 适合初学者的最佳 VSCode 扩展 2022
    适合初学者的最佳VSCode扩展2022可以说,VisualStudioCode(VSCode)是最流行的开源代码编辑器。它归微软所有,效果惊人。VSCode旨在提供一个高效的环境,为您的日常编......
  • 20220906总结
    20220906三道模拟题第一道没有什么技术含量,也没有什么算法,只要注意不出一些小失误就可以了。第二题看到数据范围之后开始犯难,感觉想到的几种写法都无法拿到满分,其中有想......
  • [Google] LeetCode 1554 Strings Differ by One Character 哈希
    Givenalistofstringsdictwhereallthestringsareofthesamelength.Returntrueifthereare2stringsthatonlydifferby1characterinthesameindex......