DEV Community

loading...

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

Collapse
nam288 profile image
Nam H. 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 Author

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
nam288 profile image
Nam H. Le • Edited

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

Forem Open with the Forem app