JS: Tricky array flatten (kind of cheating)

  • 0

    You can use the fact that the "toString" of a multidimensional array basically flattens it:

    JSON.parse(("[" + vec2d + "]").replace(/,,+/g, ",").replace(/\[,/, "[").replace(/,\]/, "]"));

    This give a simple array which is easy to iterate.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.