@@ -10464,11 +10464,11 @@
10464
10464
"code": [
10465
10465
{
10466
10466
"language": "js",
10467
- "text": "\n/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar sortArray = function(nums) {\n const counts = Array(50000 * 2 + 1).fill(0);\n const res = [];\n for(const num of nums) counts[50000 + num] += 1;\n for(let i in counts) {\n while(counts[i]--) {\n res.push(i - 50000)\n }\n }\n return res;\n};\n"
10467
+ "text": "\n/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar sortArray = function (nums) {\n const counts = Array(50000 * 2 + 1).fill(0);\n const res = [];\n for (const num of nums) counts[50000 + num] += 1;\n for (let i in counts) {\n while (counts[i]--) {\n res.push(i - 50000); \n }\n }\n return res;\n};\n"
10468
10468
},
10469
10469
{
10470
10470
"language": "js",
10471
- "text": "\nfunction swap(nums, a, b) {\n const temp = nums[a];\n nums[a] = nums[b];\n nums[b] = temp;\n}\n\nfunction helper(nums, start, end) {\n if (start >= end) return;\n const pivotIndex = start + ((end - start) >>> 1)\n const pivot = nums[pivotIndex]\n let i = start;\n let j = end;\n while (i <= j) {\n while (nums[i] < pivot) i++;\n while (nums[j] > pivot) j--;\n if (i <= j) {\n swap(nums, i, j);\n i++;\n j--;\n }\n }\n helper(nums, start, j);\n helper(nums, i, end);\n}\n\n/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar sortArray = function(nums) {\n helper(nums, 0, nums.length - 1);\n return nums;\n};\n"
10471
+ "text": "\nfunction swap(nums, a, b) {\n const temp = nums[a];\n nums[a] = nums[b];\n nums[b] = temp;\n}\n\nfunction helper(nums, start, end) {\n if (start >= end) return;\n const pivotIndex = start + ((end - start) >>> 1); \n const pivot = nums[pivotIndex]; \n let i = start;\n let j = end;\n while (i <= j) {\n while (nums[i] < pivot) i++;\n while (nums[j] > pivot) j--;\n if (i <= j) {\n swap(nums, i, j);\n i++;\n j--;\n }\n }\n helper(nums, start, j);\n helper(nums, i, end);\n}\n\n/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar sortArray = function (nums) {\n helper(nums, 0, nums.length - 1);\n return nums;\n};\n"
10472
10472
}
10473
10473
]
10474
10474
},
10753
10753
}
10754
10754
]
10755
10755
},
10756
+ "find-the-town-judge":{
10757
+ "id": "997",
10758
+ "name": "find-the-town-judge",
10759
+ "pre": [
10760
+ {
10761
+ "text": "图",
10762
+ "link": null,
10763
+ "color": "green"
10764
+ }
10765
+ ],
10766
+ "keyPoints": [
10767
+ {
10768
+ "text": "将问题抽象为图,问题转为求图的入度和出度",
10769
+ "link": null,
10770
+ "color": "blue"
10771
+ }
10772
+ ],
10773
+ "companies": [],
10774
+ "giteeSolution": "https://gitee.com/golong/leetcode/blob/master/problems/997.find-the-town-judge.md",
10775
+ "solution": "https://github.com/azl397985856/leetcode/blob/master/problems/997.find-the-town-judge.md",
10776
+ "code": [
10777
+ {
10778
+ "language": "py",
10779
+ "text": "\n\nclass Solution:\n def findJudge(self, N, trust):\n in_degree = [0] * (N + 1)\n out_degree = [0] * (N + 1)\n for a, b in trust:\n in_degree[b] += 1\n out_degree[a] += 1\n for i in range(1, N + 1):\n if in_degree[i] == N - 1 and out_degree[i] == 0:\n return i\n return -1\n\n"
10780
+ },
10781
+ {
10782
+ "language": "py",
10783
+ "text": "\nclass Solution:\n def findJudge(self, N, trust):\n count = [0] * (N + 1)\n for i, j in trust:\n count[i] -= 1\n count[j] += 1\n for i in range(1, N + 1):\n if count[i] == N - 1:\n return i\n return -1\n"
10784
+ }
10785
+ ]
10786
+ },
10756
10787
"max-consecutive-ones-iii":{
10757
10788
"id": "1004",
10758
10789
"name": "max-consecutive-ones-iii",
0 commit comments