{ "data": { "question": { "questionId": "100175", "questionFrontendId": "面试题 04.03", "categoryTitle": "LCCI", "boundTopicId": 46201, "title": "List of Depth LCCI", "titleSlug": "list-of-depth-lcci", "content": "
Given a binary tree, design an algorithm which creates a linked list of all the nodes at each depth (e.g., if you have a tree with depth D, you'll have D linked lists). Return a array containing all the linked lists.
\r\n\r\n\r\n\r\n
Example:
\r\n\r\n\r\nInput: [1,2,3,4,5,null,7,8]\r\n\r\n 1\r\n / \\ \r\n 2 3\r\n / \\ \\ \r\n 4 5 7\r\n /\r\n 8\r\n\r\nOutput: [[1],[2,3],[4,5,7],[8]]\r\n\r\n", "translatedTitle": "特定深度节点链表", "translatedContent": "
给定一棵二叉树,设计一个算法,创建含有某一深度上所有节点的链表(比如,若一棵树的深度为 D
,则会创建出 D
个链表)。返回一个包含所有深度的链表的数组。
\n\n
示例:
\n\n输入:[1,2,3,4,5,null,7,8]\n\n 1\n / \\ \n 2 3\n / \\ \\ \n 4 5 7\n /\n 8\n\n输出:[[1],[2,3],[4,5,7],[8]]\n\n", "isPaidOnly": false, "difficulty": "Medium", "likes": 71, "dislikes": 0, "isLiked": null, "similarQuestions": "[]", "contributors": [], "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": true, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"ruby\": false, \"bash\": false, \"swift\": false, \"golang\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"kotlin\": false, \"rust\": false, \"php\": false, \"typescript\": false, \"racket\": false, \"erlang\": false, \"elixir\": false}", "topicTags": [ { "name": "Tree", "slug": "tree", "translatedName": "树", "__typename": "TopicTagNode" }, { "name": "Breadth-First Search", "slug": "breadth-first-search", "translatedName": "广度优先搜索", "__typename": "TopicTagNode" }, { "name": "Linked List", "slug": "linked-list", "translatedName": "链表", "__typename": "TopicTagNode" }, { "name": "Binary Tree", "slug": "binary-tree", "translatedName": "二叉树", "__typename": "TopicTagNode" } ], "companyTagStats": null, "codeSnippets": [ { "lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n vector