字符串匹配问题
来源:互联网 发布:大数据时代来临 编辑:程序博客网 时间:2024/05/21 17:46
问题描述:
Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.
The brackets must close in the correct order, “()” and “()[]{}” are all valid but “(]” and “([)]” are not.
给定一个字符串,只包含字符“(”、“””、“{”、“}”、“[”和“”),确定输入字符串是否有效。
括号必须以正确的顺序关闭,“()”和“()”{“}”都是有效的,但“()和[([ ] ] ] ]不是。
<!DOCTYPE html><html><head> <meta charset="utf-8"> <title></title></head><body><script type="text/javascript">var isValid = function isValid(s) { debugger var valid = true, pair = { '(': ')', '[': ']', '{': '}' }, nowWaitingFor = []; for (var i = 0; i < s.length; i++) { var nowChar = s.charAt(i); if (nowChar.match(/[(\[\{]/)) { nowWaitingFor.unshift(pair[nowChar]); } else if (nowChar.match(/[)\]\}]/)) { if (nowWaitingFor[0] !== nowChar) { valid = false; break; } else { nowWaitingFor.splice(0, 1); } } } if (nowWaitingFor.length !== 0) { valid = false; } return valid;};console.log(isValid("()})"))</script></body></html>
阅读全文
0 0
- 字符串查找匹配问题
- 字符串匹配问题
- 中文字符串匹配问题
- 字符串匹配问题
- 字符串匹配问题
- 字符串匹配问题
- 字符串匹配问题
- 字符串匹配问题
- js 字符串 匹配问题
- 字符串匹配问题
- 字符串匹配问题
- 字符串匹配问题
- 字符串匹配问题
- 字符串匹配问题
- 字符串匹配问题
- 字符串通配符匹配问题
- 字符串匹配问题
- 1063:字符串匹配问题
- ros中kobuki(turtlebot)+rplidar 跑gmapping 发布时间:2016年11月23日 13:32:20 浏览数:828次 来自:kint_zhao 由于手头目
- mybatis详解-(7)增删改查
- redis学习
- 飞机大战(关于JavaFX注意点)
- 深入理解C++中public、protected及private用法
- 字符串匹配问题
- 最长重复词问题(java)
- 百度天工IoT 快速上手
- 使用jquery实现文字滚动,鼠标悬停效果
- android自定义的RadioButton
- Android线程优先级
- 在Android手机上运行Windows系统
- Java中的三种代理模式
- linux 下shell 脚本编程之退出码