My submission is Javascript


  • 0
    K

    var isValid = function(s) {

    var stack = [];

    for(var i=0;i < s.length;i++)
    {

        if(s[i]=='('||s[i]=='['||s[i]=='{')stack.push(s[i]);
        else {
         
            if(stack.length === 0||!match(s[i], stack.pop()))return false;
        }
    }
    
    return stack.length === 0;
    

    };

    var match= function(c, pop value)
    {

    if(c==')' && popvalue=='(')  return true;
    else if(c==']' && popvalue=='[')return true;
    else if(c=='}'&& popvalue=='{')return true;
    else return false;
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.