I checked some of the answers shared so far. Most of them did not pass the test case of [1,[4,[6,[] ] ]] which leads to a multi-level empty list. So, I am not sure whether these solutions got accepted or not. If they do, then the test cases of this problem are too weak.
I think Leecode needs to do a better QA job before releasing any problem set. Instead, they paid ppl to create problems for $50 each and get the misleading results.
This is not a good sign.....
Does the result of the test case [1,[4,[6,[] ] ]] should be 39? However, the system give the result as 17.