https://leetcode.com/problems/valid-parentheses/
I wanted to know if there is a better way of doing this. When I see this problem I first thought of a recursive-descent parser and here's my solution:
struct Lexer {
char* cur;
char* end;
inline void adv() {
++cur;
}
inline bool ok() {
return cur < end;
}
inline char peek() {
return *cur;
}
};
class Solution {
public:
/*
Program = Expr*;
Expr => '(' Expr* ')'
| '[' Expr* ']'
| '{' Expr* '}'
|
;
*/
LeetCode
Can you solve this real interview question? Valid Parentheses - Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
An input string is valid if:
- Open brackets must be closed by the same type of brackets.
- Open brackets must be closed in the correct order.
- Every clo...