GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • LeetCodeJavascript.com
  • Star on GitHub

This view

  • Original page
  • New address

GeezerVison is showing leetcodejavascript.com — #385 - Mini Parser - LeetCode JavaScript Solutions

Back to all solutions

#385 - Mini Parser

Medium • View on LeetCode • View on GitHub
String Depth-First Search Stack

Problem Description

Given a string s represents the serialization of a nested list, implement a parser to deserialize it and return the deserialized NestedInteger.

Each element is either an integer or a list whose elements may also be integers or other lists.

Solution

/**
 * @param {string} s
 * @return {NestedInteger}
 */
var deserialize = function(s) {
  return traverse(JSON.parse(s));

  function traverse(str) {
    if (Number.isInteger(str)) {
      return new NestedInteger(str);
    }
    const value = new NestedInteger();
    for (const s of str) {
      value.add(traverse(s));
    }
    return value;
  };
};
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.