Created
February 2, 2018 14:10
-
-
Save caglarorhan/9883d0e93d4dd120366c4a036d33243b to your computer and use it in GitHub Desktop.
Valid Parentheses -from leetcode.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var isValid = function(s) { | |
var rV=true; // default | |
var f=''; | |
for(var x=0; x<s.length; x++){ | |
if('()[]{}'.indexOf(s[x])>-1){ | |
f+=s[x]; | |
} | |
} | |
while((f.indexOf('[]')>=0) || (f.indexOf('()')>=0) || (f.indexOf('{}')>=0)){ | |
f=f.replace('[]','');f=f.replace('()','');f=f.replace('{}',''); | |
} | |
if(f.length>0){ rV=false;} | |
return rV; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.