Skip to content

Instantly share code, notes, and snippets.

@GeuntaBuwono
Created February 2, 2023 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GeuntaBuwono/50ffc65fa3537078714e7ca48547a1ba to your computer and use it in GitHub Desktop.
Save GeuntaBuwono/50ffc65fa3537078714e7ca48547a1ba to your computer and use it in GitHub Desktop.
LeetCode Valid Parentheses
/**
* @param {string} s
* @return {boolean}
*/
var isValid = function(s) {
const charStack = []
for (i=0; i < s.length; i++){
let currentChar = s[i];
switch(currentChar) {
case '(': charStack.push(')');
break;
case '[': charStack.push(']');
break;
case '{': charStack.push('}')
break;
default:
if(currentChar !== charStack.pop()) return false
}
}
return charStack.length === 0;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment