← 返回 bytedance 的题目列表Flatten HTML Tag
类型:online_judge
Problem: Flatten HTML Tag
Given a JSON-like object representing the nested structure of HTML tags, flatten this object into a structure where each tag is a top-level element. The input is a JSON-like object representing nested HTML elements, and the output should be a flattened structure.
Input
A JSON-like object representing the nested structure of HTML elements.
Output
A flattened structure of the object.
Example
{
"tag": "div",
"children": [
{
"tag": "span",
"children": []
},
{
"tag": "b",
"children": [
{
"tag": "i",
"children": []
}
]
}
]
}
The output should be:
[
{ "tag": "div" },
{ "tag": "span" },
{ "tag": "b" },
{ "tag": "i" }
]
Notes
Ensure that all tags appear in the order of their occurrence.
Each tag is unique; only the tag name needs to be outputted.
Example
Input
{"tag":"root","children":[]}