Created
October 14, 2020 20:49
-
-
Save dabsclement/580e92841dc32990b523d76512cb95b3 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* @param {string} s | |
* @return {boolean} | |
*/ | |
var isValid = function(s) { | |
const par = { | |
"(": ")", | |
"{": "}", | |
"[": "]", | |
}; | |
const rep = []; | |
for (let i = 0; i < s.length; i++) { | |
if (par[s[i]]) { | |
rep.push(par[s[i]]); | |
} else { | |
if (rep.pop() !== s[i]) { | |
return false; | |
} | |
} | |
} | |
return rep.length === 0; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment