leetcode 019_Valid Parentheses

来源:互联网 发布:开微店用什么软件好 编辑:程序博客网 时间:2024/05/22 07:04

判断括号是否正确;

bool isValid(string s){int j = 0,n = 0;string stack = s;while (n != s.size()){switch (s[n]){case '(':stack[j++] = '(';break;case '[':stack[j++] = '[';break;case '{':stack[j++] = '{';break;case '}':if (j > 0 && stack[--j] == '{'){}elsereturn false;break;case ']':if (j > 0 && stack[--j] == '['){}elsereturn false;break;case ')':if (j > 0 && stack[--j] == '('){}elsereturn false;break;default:break;}++n;}return (j == 0 );}


0 0
原创粉丝点击