Skip to content

Latest commit

 

History

History
32 lines (27 loc) · 669 Bytes

File metadata and controls

32 lines (27 loc) · 669 Bytes

括号问题 parentheses

use stack

一种括号

left: 待匹配的左括号数量 int left = 0; for (char c : str) { if (c == '(') left++; else // 遇到右括号 left--;

    if (left < 0)
        return false;
}
return left == 0;

多种括号

stack: 待匹配的左括号

pseudo code for balance string

function is_balanced_parentheses(string) balance = 0 for each char in the string if char == "(" balance = balance + 1 if char == ")" balance = balance - 1 if balance < 0 return false return balance == 0