1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/originData/employee-importance.json

144 lines
21 KiB
JSON
Raw Normal View History

2022-03-27 20:46:41 +08:00
{
"data": {
"question": {
"questionId": "690",
"questionFrontendId": "690",
"categoryTitle": "Algorithms",
"boundTopicId": 1118,
"title": "Employee Importance",
"titleSlug": "employee-importance",
2023-12-09 18:42:21 +08:00
"content": "<p>You have a data structure of employee information, including the employee&#39;s unique ID, importance value, and direct subordinates&#39; IDs.</p>\n\n<p>You are given an array of employees <code>employees</code> where:</p>\n\n<ul>\n\t<li><code>employees[i].id</code> is the ID of the <code>i<sup>th</sup></code> employee.</li>\n\t<li><code>employees[i].importance</code> is the importance value of the <code>i<sup>th</sup></code> employee.</li>\n\t<li><code>employees[i].subordinates</code> is a list of the IDs of the direct subordinates of the <code>i<sup>th</sup></code> employee.</li>\n</ul>\n\n<p>Given an integer <code>id</code> that represents an employee&#39;s ID, return <em>the <strong>total</strong> importance value of this employee and all their direct and indirect subordinates</em>.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/05/31/emp1-tree.jpg\" style=\"width: 400px; height: 258px;\" />\n<pre>\n<strong>Input:</strong> employees = [[1,5,[2,3]],[2,3,[]],[3,3,[]]], id = 1\n<strong>Output:</strong> 11\n<strong>Explanation:</strong> Employee 1 has an importance value of 5 and has two direct subordinates: employee 2 and employee 3.\nThey both have an importance value of 3.\nThus, the total importance value of employee 1 is 5 + 3 + 3 = 11.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/05/31/emp2-tree.jpg\" style=\"width: 362px; height: 361px;\" />\n<pre>\n<strong>Input:</strong> employees = [[1,2,[5]],[5,-3,[]]], id = 5\n<strong>Output:</strong> -3\n<strong>Explanation:</strong> Employee 5 has an importance value of -3 and has no direct subordinates.\nThus, the total importance value of employee 5 is -3.\n</pre>\n\n<p>&nbsp;</p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= employees.length &lt;= 2000</code></li>\n\t<li><code>1 &lt;= employees[i].id &lt;= 2000</code></li>\n\t<li>All <code>employees[i].id</code> are <strong>unique</strong>.</li>\n\t<li><code>-100 &lt;= employees[i].importance &lt;= 100</code></li>\n\t<li>One employee has at most one direct leader and may have several subordinates.</li>\n\t<li>The IDs in <code>employees[i].subordinates</code> are valid IDs.</li>\n</ul>\n",
2022-03-27 20:46:41 +08:00
"translatedTitle": "员工的重要性",
"translatedContent": "<p>给定一个保存员工信息的数据结构,它包含了员工 <strong>唯一的 id </strong><strong>重要度 </strong>和 <strong>直系下属的 id </strong>。</p>\n\n<p>比如,员工 1 是员工 2 的领导,员工 2 是员工 3 的领导。他们相应的重要度为 15 , 10 , 5 。那么员工 1 的数据结构是 [1, 15, [2]] ,员工 2的 数据结构是 [2, 10, [3]] ,员工 3 的数据结构是 [3, 5, []] 。注意虽然员工 3 也是员工 1 的一个下属,但是由于 <strong>并不是直系</strong> 下属,因此没有体现在员工 1 的数据结构中。</p>\n\n<p>现在输入一个公司的所有员工信息,以及单个员工 id ,返回这个员工和他所有下属的重要度之和。</p>\n\n<p> </p>\n\n<p><strong>示例:</strong></p>\n\n<pre>\n<strong>输入:</strong>[[1, 5, [2, 3]], [2, 3, []], [3, 3, []]], 1\n<strong>输出:</strong>11\n<strong>解释:</strong>\n员工 1 自身的重要度是 5 ,他有两个直系下属 2 和 3 ,而且 2 和 3 的重要度均为 3 。因此员工 1 的总重要度是 5 + 3 + 3 = 11 。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li>一个员工最多有一个<strong> 直系 </strong>领导,但是可以有多个 <strong>直系 </strong>下属</li>\n\t<li>员工数量不超过 2000 。</li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Medium",
2023-12-09 18:42:21 +08:00
"likes": 286,
2022-03-27 20:46:41 +08:00
"dislikes": 0,
"isLiked": null,
2023-12-09 18:42:21 +08:00
"similarQuestions": "[{\"title\": \"Nested List Weight Sum\", \"titleSlug\": \"nested-list-weight-sum\", \"difficulty\": \"Medium\", \"translatedTitle\": \"\\u5d4c\\u5957\\u5217\\u8868\\u6743\\u91cd\\u548c\", \"isPaidOnly\": true}]",
2022-03-27 20:46:41 +08:00
"contributors": [],
2023-12-09 18:42:21 +08:00
"langToValidPlayground": "{\"cpp\": false, \"java\": true, \"python\": true, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}",
2022-03-27 20:46:41 +08:00
"topicTags": [
{
"name": "Depth-First Search",
"slug": "depth-first-search",
"translatedName": "深度优先搜索",
"__typename": "TopicTagNode"
},
{
"name": "Breadth-First Search",
"slug": "breadth-first-search",
"translatedName": "广度优先搜索",
"__typename": "TopicTagNode"
},
{
"name": "Hash Table",
"slug": "hash-table",
"translatedName": "哈希表",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
"lang": "C++",
"langSlug": "cpp",
"code": "/*\n// Definition for Employee.\nclass Employee {\npublic:\n int id;\n int importance;\n vector<int> subordinates;\n};\n*/\n\nclass Solution {\npublic:\n int getImportance(vector<Employee*> employees, int id) {\n \n }\n};",
"__typename": "CodeSnippetNode"
},
{
"lang": "Java",
"langSlug": "java",
"code": "/*\n// Definition for Employee.\nclass Employee {\n public int id;\n public int importance;\n public List<Integer> subordinates;\n};\n*/\n\nclass Solution {\n public int getImportance(List<Employee> employees, int id) {\n \n }\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "Python",
"langSlug": "python",
"code": "\"\"\"\n# Definition for Employee.\nclass Employee(object):\n def __init__(self, id, importance, subordinates):\n \t#################\n :type id: int\n :type importance: int\n :type subordinates: List[int]\n #################\n self.id = id\n self.importance = importance\n self.subordinates = subordinates\n\"\"\"\n\nclass Solution(object):\n def getImportance(self, employees, id):\n \"\"\"\n :type employees: List[Employee]\n :type id: int\n :rtype: int\n \"\"\"\n ",
"__typename": "CodeSnippetNode"
},
{
"lang": "Python3",
"langSlug": "python3",
"code": "\"\"\"\n# Definition for Employee.\nclass Employee:\n def __init__(self, id: int, importance: int, subordinates: List[int]):\n self.id = id\n self.importance = importance\n self.subordinates = subordinates\n\"\"\"\n\nclass Solution:\n def getImportance(self, employees: List['Employee'], id: int) -> int:\n ",
"__typename": "CodeSnippetNode"
},
{
"lang": "C#",
"langSlug": "csharp",
"code": "/*\n// Definition for Employee.\nclass Employee {\n public int id;\n public int importance;\n public IList<int> subordinates;\n}\n*/\n\nclass Solution {\n public int GetImportance(IList<Employee> employees, int id) {\n \n }\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "JavaScript",
"langSlug": "javascript",
"code": "/**\n * Definition for Employee.\n * function Employee(id, importance, subordinates) {\n * this.id = id;\n * this.importance = importance;\n * this.subordinates = subordinates;\n * }\n */\n\n/**\n * @param {Employee[]} employees\n * @param {number} id\n * @return {number}\n */\nvar GetImportance = function(employees, id) {\n \n};",
"__typename": "CodeSnippetNode"
},
{
2023-12-09 18:42:21 +08:00
"lang": "TypeScript",
"langSlug": "typescript",
"code": "/**\n * Definition for Employee.\n * class Employee {\n * id: number\n * importance: number\n * subordinates: number[]\n * constructor(id: number, importance: number, subordinates: number[]) {\n * this.id = (id === undefined) ? 0 : id;\n * this.importance = (importance === undefined) ? 0 : importance;\n * this.subordinates = (subordinates === undefined) ? [] : subordinates;\n * }\n * }\n */\n\nfunction getImportance(employees: Employee[], id: number): number {\n\t\n};",
2022-03-27 20:46:41 +08:00
"__typename": "CodeSnippetNode"
},
{
2023-12-09 18:42:21 +08:00
"lang": "PHP",
"langSlug": "php",
"code": "/**\n * Definition for Employee.\n * class Employee {\n * public $id = null;\n * public $importance = null;\n * public $subordinates = array();\n * function __construct($id, $importance, $subordinates) {\n * $this->id = $id;\n * $this->importance = $importance;\n * $this->subordinates = $subordinates;\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Employee[] $employees\n * @param Integer $id\n * @return Integer\n */\n function getImportance($employees, $id) {\n \n }\n}",
2022-03-27 20:46:41 +08:00
"__typename": "CodeSnippetNode"
},
{
2023-12-09 18:42:21 +08:00
"lang": "Swift",
"langSlug": "swift",
"code": "/**\n * Definition for Employee.\n * public class Employee {\n * public var id: Int\n * public var importance: Int\n * public var subordinates: [Int]\n * public init(_ id: Int, _ importance: Int, _ subordinates: [Int]) {\n * self.id = id\n * self.importance = importance\n * self.subordinates = subordinates\n * }\n * }\n */\n\nclass Solution {\n func getImportance(_ employees: [Employee], _ id: Int) -> Int {\n \n }\n}",
2022-03-27 20:46:41 +08:00
"__typename": "CodeSnippetNode"
},
{
"lang": "Kotlin",
"langSlug": "kotlin",
"code": "/*\n *\t// Definition for Employee.\n *\tclass Employee {\n *\t\tvar id:Int = 0\n *\t\tvar importance:Int = 0\n *\t\tvar subordinates:List<Int> = listOf()\n *\t}\n */\n\nclass Solution {\n fun getImportance(employees: List<Employee?>, id: Int): Int {\n \n }\n}",
"__typename": "CodeSnippetNode"
},
{
2023-12-09 18:42:21 +08:00
"lang": "Go",
"langSlug": "golang",
"code": "/**\n * Definition for Employee.\n * type Employee struct {\n * Id int\n * Importance int\n * Subordinates []int\n * }\n */\n\nfunc getImportance(employees []*Employee, id int) int {\n \n}",
2022-03-27 20:46:41 +08:00
"__typename": "CodeSnippetNode"
},
{
2023-12-09 18:42:21 +08:00
"lang": "Ruby",
"langSlug": "ruby",
"code": "=begin\n# Definition for Employee.\nclass Employee\n attr_accessor :id, :importance, :subordinates\n def initialize( id, importance, subordinates)\n @id = id\n @importance = importance\n @subordinates = subordinates\n end\nend\n=end\n\n# @param {Employee} employees\n# @param {Integer} id\n# @return {Integer}\ndef get_importance(employees, id)\n \nend",
"__typename": "CodeSnippetNode"
},
{
"lang": "Scala",
"langSlug": "scala",
"code": "/*\n// Definition for Employee.\nclass Employee() {\n var id: Int = 0\n var importance: Int = 0\n var subordinates: List[Int] = List()\n};\n*/\n\nobject Solution {\n def getImportance(employees: List[Employee], id: Int): Int = {\n \n }\n}",
2022-03-27 20:46:41 +08:00
"__typename": "CodeSnippetNode"
}
],
2023-12-09 18:42:21 +08:00
"stats": "{\"totalAccepted\": \"67.3K\", \"totalSubmission\": \"102.1K\", \"totalAcceptedRaw\": 67255, \"totalSubmissionRaw\": 102052, \"acRate\": \"65.9%\"}",
2022-03-27 20:46:41 +08:00
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "[[1,5,[2,3]],[2,3,[]],[3,3,[]]]\n1",
"metaData": "{\n \"name\": \"getImportance\",\n \"params\": [\n {\n \"name\": \"employees\",\n \"type\": \"list<string>\"\n },\n {\n \"name\": \"id\",\n \"type\": \"integer\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\n },\n \"languages\": [\n \"cpp\",\n \"java\",\n \"python\",\n \"ruby\",\n \"python3\",\n \"kotlin\",\n \"scala\",\n \"csharp\",\n \"javascript\",\n \"swift\",\n \"golang\",\n \"php\",\n \"typescript\"\n ],\n \"manual\": true\n}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [],
"enableRunCode": true,
2023-12-09 18:42:21 +08:00
"envInfo": "{\"cpp\":[\"C++\",\"<p>\\u7248\\u672c\\uff1a<code>clang 11<\\/code> \\u91c7\\u7528\\u6700\\u65b0C++ 20\\u6807\\u51c6\\u3002<\\/p>\\r\\n\\r\\n<p>\\u7f16\\u8bd1\\u65f6\\uff0c\\u5c06\\u4f1a\\u91c7\\u7528<code>-O2<\\/code>\\u7ea7\\u4f18\\u5316\\u3002<a href=\\\"https:\\/\\/github.com\\/google\\/sanitizers\\/wiki\\/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer<\\/a> \\u4e5f\\u88ab\\u5f00\\u542f\\u6765\\u68c0\\u6d4b<code>out-of-bounds<\\/code>\\u548c<code>use-after-free<\\/code>\\u9519\\u8bef\\u3002<\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u4f7f\\u7528\\u65b9\\u4fbf\\uff0c\\u5927\\u90e8\\u5206\\u6807\\u51c6\\u5e93\\u7684\\u5934\\u6587\\u4ef6\\u5df2\\u7ecf\\u88ab\\u81ea\\u52a8\\u5bfc\\u5165\\u3002<\\/p>\"],\"java\":[\"Java\",\"<p>\\u7248\\u672c\\uff1a<code>OpenJDK 17<\\/code>\\u3002\\u53ef\\u4ee5\\u4f7f\\u7528Java 8\\u7684\\u7279\\u6027\\u4f8b\\u5982\\uff0clambda expressions \\u548c stream API\\u3002<\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u65b9\\u4fbf\\u8d77\\u89c1\\uff0c\\u5927\\u90e8\\u5206\\u6807\\u51c6\\u5e93\\u7684\\u5934\\u6587\\u4ef6\\u5df2\\u88ab\\u5bfc\\u5165\\u3002<\\/p>\\r\\n\\r\\n<p>\\u5305\\u542b Pair \\u7c7b: https:\\/\\/docs.oracle.com\\/javase\\/8\\/javafx\\/api\\/javafx\\/util\\/Pair.html <\\/p>\"],\"python\":[\"Python\",\"<p>\\u7248\\u672c\\uff1a <code>Python 2.7.12<\\/code><\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u65b9\\u4fbf\\u8d77\\u89c1\\uff0c\\u5927\\u90e8\\u5206\\u5e38\\u7528\\u5e93\\u5df2\\u7ecf\\u88ab\\u81ea\\u52a8 \\u5bfc\\u5165\\uff0c\\u5982\\uff1a<a href=\\\"https:\\/\\/docs.python.org\\/2\\/library\\/array.html\\\" target=\\\"_blank\\\">array<\\/a>, <a href=\\\"https:\\/\\/docs.python.org\\/2\\/library\\/bisect.html\\\" target=\\\"_blank\\\">bisect<\\/a>, <a href=\\\"https:\\/\\/docs.python.org\\/2\\/library\\/collections.html\\\" target=\\\"_blank\\\">collections<\\/a>\\u3002\\u5982\\u679c\\u60a8\\u9700\\u8981\\u4f7f\\u7528\\u5176\\u4ed6\\u5e93\\u51fd\\u6570\\uff0c\\u8bf7\\u81ea\\u884c\\u5bfc\\u5165\\u3002<\\/p>\\r\\n\\r\\n<p>\\u6ce8\\u610f Python 2.7 <a href=\\\"https:\\/\\/www.python.org\\/dev\\/peps\\/pep-0373\\/\\\" target=\\\"_blank\\\">\\u5c06\\u57282020\\u5e74\\u540e\\u4e0d\\u518d\\u7ef4\\u62a4<\\/a>\\u3002 \\u5982\\u60f3\\u4f7f\\u7528\\u6700\\u65b0\\u7248\\u7684Python\\uff0c\\u8bf7\\u9009\\u62e9Python 3\\u3002<\\/p>\"],\"csharp\":[\"C#\",\"<p><a href=\\\"https:\\/\\/docs.microsoft.com\\/en-us\\/dotnet\\/csharp\\/whats-new\\/csharp-9\\\" target=\\\"_blank\\\">C# 10<\\/a> \\u8fd0\\u884c\\u5728 .NET 6 \\u4e0a<\\/p>\"],\"javascript\":[\"JavaScript\",\"<p>\\u7248\\u672c\\uff1a<code>Node.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n<p>\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a <code>--harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f <a href=\\\"http:\\/\\/node.green\\/\\\" target=\\\"_blank\\\">\\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"ruby\":[\"Ruby\",\"<p>\\u4f7f\\u7528<code>Ruby 3.1<\\/code>\\u6267\\u884c<\\/p>\\r\\n\\r\\n<p>\\u4e00\\u4e9b\\u5e38\\u7528\\u7684\\u6570\\u636e\\u7ed3\\u6784\\u5df2\\u5728 Algorithms \\u6a21\\u5757\\u4e2d\\u63d0\\u4f9b\\uff1ahttps:\\/\\/www.rubydoc.info\\/github\\/kanwei\\/algorithms\\/Algorithms<\\/p>\"],\"swift\":[\"Swift\",\"<p>\\u7248\\u672c\\uff1a<code>Swift 5.5.2<\\/code><\\/p>\\r\\n\\r\\n<p>\\u6211\\u4eec\\u901a\\u5e38\\u4fdd\\u8bc1\\u66f4\\u65b0\\u5230 <a href=\\\"https:\\/\\/swift.org\\/download\\/\\\" target=\\\"_bla
2022-03-27 20:46:41 +08:00
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "[[1,5,[2,3]],[2,3,[]],[3,3,[]]]\n1\n[[1,2,[5]],[5,-3,[]]]\n5",
"__typename": "QuestionNode"
}
}
}