shlogg · Early preview
Rakesh Reddy Peddamallu @rakesh678219

Validating Brackets In JavaScript With Stack Approach

We loop through chars of s, if its a closing bracket we compare with last element in stack, it should be appropriate as define in map otherwise we return false. JavaScript Code: https://example.com/jscode

Approach
We loop through chars of s , if its a closing bracket we compare with last element in stack , it should be appropriate as define in map otherwise we return false
Javascript Code

/**
 * @param {string} s
 * @return {boolean}
 */
var isValid = function (s) {
    const myMap = {
        "}": "{",
        "]": "[",
        ")": "("
    };
    let myStack = [];
    for (let char of s) {
        if (char in myMap) {  // If it's a closing bracket
            if (myStack.length === 0 || myStack.pop() !== myMap[char]) {
                return false;
            }
        } else {  // If it's...