Skip to content

Instantly share code, notes, and snippets.

@caglarorhan
Created February 2, 2018 14:10
Show Gist options
  • Save caglarorhan/9883d0e93d4dd120366c4a036d33243b to your computer and use it in GitHub Desktop.
Save caglarorhan/9883d0e93d4dd120366c4a036d33243b to your computer and use it in GitHub Desktop.
Valid Parentheses -from leetcode.com
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;
};
@caglarorhan
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment