DEV Community

Discussion on: Valid parentheses, solving a Facebook interview question.

Collapse
 
namhle profile image
Nam Hoang Le

It’s me again. Here’s my solution.

function isValid(s) {
    const t = s.replace(/\(\)|\[\]|\{\}/g, "");
    return s == t ? !s : isValid(t);
};
Collapse
 
akhilpokle profile image
Akhil

Test it here: leetcode.com/problems/valid-parent...

As far as I know, the regex will manipulate string and string manipulation is a bit time consuming heavy in javascript.

But smart and concise code though !

Collapse
 
namhle profile image
Nam Hoang Le • Edited

It’s true. C/C++ can solve it in almost 0ms.