Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 925d3bd

Browse files
committed
Add solution #385
1 parent 288fe12 commit 925d3bd

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

0385-mini-parser.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
};

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@
303303
382|[Linked List Random Node](./0382-linked-list-random-node.js)|Medium|
304304
383|[Ransom Note](./0383-ransom-note.js)|Easy|
305305
384|[Shuffle an Array](./0384-shuffle-an-array.js)|Medium|
306+
385|[Mini Parser](./0385-mini-parser.js)|Medium|
306307
387|[First Unique Character in a String](./0387-first-unique-character-in-a-string.js)|Easy|
307308
389|[Find the Difference](./0389-find-the-difference.js)|Easy|
308309
392|[Is Subsequence](./0392-is-subsequence.js)|Easy|

0 commit comments

Comments
 (0)