Given the string of parentheses only, write the function to check if they are balanced. ((())) is ba

function isBalanced(str){
  var stack = new Stack();
  for(var c=0;c<str.length;c++){
    var chr = str[c];
    if(isOpenBracket(chr)){
      stack.push(chr);
    }
    else if(isCloseBracket(chr)){
      var openBracket = stack.pop();
      if(!bracketsMatch(openBracket, chr))
        return false;
    }
  }
  return true;
}

你可能感兴趣的:(Given the string of parentheses only, write the function to check if they are balanced. ((())) is ba)