In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
Today, the editor will share with you the relevant knowledge points of case analysis of JavaScript interview questions. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
Topic description
There is a nested array given as a string, and write a parser to deserialize it.
The elements of an array are integers or arrays of the same form.
Note: you can assume that this string follows the following rules:
The string is not empty
The string does not contain spaces
The string contains only the numbers 0-9, [, -,], and the comma ",".
Sample 1
Given the string s = "234", a NestedInteger object containing only one integer 234 is returned.
Example two
Given the string s = "[123,456, [789]", a NestedInteger object containing two elements is returned:
An integer 123
A List for NestedInteger that contains two elements:
An integer 456
A List for NestedInteger that contains one element:
An integer 789
Analysis of ideas for solving problems
This is a medium-difficulty string processing problem, the main difficulty is that the level of logical thinking, each case can not be missed.
For a brief analysis, this question needs to be analyzed layer by layer, and ends when it reaches the innermost layer. For this hierarchical problem, it is obviously suitable for two solutions, one is to use Stack, the other is recursive. The two solutions are only differences in code writing, in fact, there is no difference in essence (Stack can be regarded as analog recursion), so the reference program only gives a solution using Stack, recursion is similar.
In-depth analysis
If you encounter a "[" symbol in a string, you need to open a new layer (that is, stack).
If the "]" symbol is encountered in the string, it indicates the end of this layer (that is, the stack is required). But at the end of the first layer, because the upper layer contains the pop-up layer, it needs to be added to the upper layer (the top of the stack behind the pop-up stack).
If you encounter "," in a string, you only need to deal with the case in front of the number (because the case in front of the array has been dealt with when you encounter "]"), that is, add the number to the current layer (that is, the top layer of the stack).
Note a special case: a case that contains only one number (such as example 1) requires additional processing (because it does not have any symbols).
Reference code
The above is all the contents of the article "case Analysis of JavaScript interview questions". Thank you for your reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.