File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * 385. Mini Parser
3+ * https://leetcode.com/problems/mini-parser/
4+ * Difficulty: Medium
5+ *
6+ * Given a string s represents the serialization of a nested list, implement a parser to deserialize
7+ * it and return the deserialized NestedInteger.
8+ *
9+ * Each element is either an integer or a list whose elements may also be integers or other lists.
10+ */
11+
12+ /**
13+ * @param {string } s
14+ * @return {NestedInteger }
15+ */
16+ var deserialize = function ( s ) {
17+ return traverse ( JSON . parse ( s ) ) ;
18+
19+ function traverse ( str ) {
20+ if ( Number . isInteger ( str ) ) {
21+ return new NestedInteger ( str ) ;
22+ }
23+ const value = new NestedInteger ( ) ;
24+ for ( const s of str ) {
25+ value . add ( traverse ( s ) ) ;
26+ }
27+ return value ;
28+ } ;
29+ } ;
Original file line number Diff line number Diff line change 303303382|[ Linked List Random Node] ( ./0382-linked-list-random-node.js ) |Medium|
304304383|[ Ransom Note] ( ./0383-ransom-note.js ) |Easy|
305305384|[ Shuffle an Array] ( ./0384-shuffle-an-array.js ) |Medium|
306+ 385|[ Mini Parser] ( ./0385-mini-parser.js ) |Medium|
306307387|[ First Unique Character in a String] ( ./0387-first-unique-character-in-a-string.js ) |Easy|
307308389|[ Find the Difference] ( ./0389-find-the-difference.js ) |Easy|
308309392|[ Is Subsequence] ( ./0392-is-subsequence.js ) |Easy|
You can’t perform that action at this time.
0 commit comments