DEV Community

loading...

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

Collapse
nam288 profile image
Nam H. Le • Edited

You can check a number is not equal to zero by if (n) {} or check empty string by if (!s) ....
Of course, just use object literal for you map. :)

The last statement should be return !stack.length.

Bonus point: we can solve it shorter by using recursion and String replace method.

Collapse
akhilpokle profile image
Akhil Author

I wrote this way for code readability :)

Collapse
nam288 profile image
Nam H. Le • Edited

Yes, that way is better for products. But the boundary between readability and cleaning is not always clear. :)

Thread Thread
akhilpokle profile image
Akhil Author

True that.

Forem Open with the Forem app